﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using HML.Design;
using System.Runtime.InteropServices;
using System.Reflection;

namespace HML
{
    /// <summary>
    /// TabControlPlus(TabControl增强版)
    /// </summary> 
    [Description("TabControlPlus(TabControl增强版)")]
    [DefaultProperty("TabPages")]
    [DefaultEvent("SelectedIndexChanged")]
    [TypeConverter(typeof(TabControlPlusConverter))]
    [Designer(typeof(TabControlPlusDesigner))]
    [ToolboxItem(true)]
    [ToolboxBitmap(typeof(TabControlPlus), "Controls.TabControlPlus.Resources.TabControlPlus.bmp")]
    public class TabControlPlus : DpiControl, ISkinObject
    {
        #region 主题

        private SkinObjectXmlMetadata skinObjectXmlMetadata = null;
        /// <summary>
        /// 主题对象在主题文件信息
        /// </summary>
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual SkinObjectXmlMetadata SkinObjectXmlMetadata
        {
            get
            {
                if (this.skinObjectXmlMetadata == null)
                    this.skinObjectXmlMetadata = new SkinObjectXmlMetadata(Assembly.GetAssembly(typeof(TabControlPlus)).GetName().Name, typeof(TabControlPlus).Name);

                return this.skinObjectXmlMetadata;
            }
        }

        private SkinController skinController = null;
        /// <summary>
        /// 主题控制器
        /// </summary>
        [Description("主题控制器")]
        [Category("杂项")]
        [PropertyOrder(-360)]
        [DefaultValue(null)]
        [RefreshProperties(RefreshProperties.All)]
        public virtual SkinController SkinController
        {
            get { return this.skinController; }
            set
            {
                if (this.skinController == value)
                    return;

                if (this.skinController != null)
                    this.skinController.RemoveSkinObject(this);

                this.skinController = value;

                if (this.skinController != null)
                    this.skinController.AddSkinObject(this);
            }
        }

        private SkinEnabledState skinEnabled = SkinEnabledState.Auto;
        /// <summary>
        /// 主题是否启用
        /// </summary>
        [Description("主题是否启用")]
        [Category("杂项")]
        [PropertyOrder(-300)]
        [DefaultValue(SkinEnabledState.Auto)]
        [RefreshProperties(RefreshProperties.All)]
        public virtual SkinEnabledState SkinEnabled
        {
            get { return this.skinEnabled; }
            set
            {
                if (this.skinEnabled == value)
                    return;

                this.skinEnabled = value;
                this.OnSkinChanged();
            }
        }

        private SkinStyle skinStyle = SkinStyle.Normal;
        /// <summary>
        /// 主题风格
        /// </summary>
        [Description("主题风格")]
        [Category("杂项")]
        [PropertyOrder(-260)]
        [DefaultValue(SkinStyle.Normal)]
        [RefreshProperties(RefreshProperties.All)]
        public virtual SkinStyle SkinStyle
        {
            get { return this.skinStyle; }
            set
            {
                if (this.skinStyle == value)
                    return;

                this.skinStyle = value;
                this.OnSkinChanged();
            }
        }

        private StyleAppearanceObject stateAppearance;
        /// <summary>
        /// 风格外观
        /// </summary>
        [Description("风格外观")]
        [Category("杂项")]
        [PropertyOrder(-200)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public StyleAppearanceObject StyleAppearance
        {
            get
            {
                if (this.stateAppearance == null)
                    this.stateAppearance = new StyleAppearanceObject(this, null);
                return this.stateAppearance;
            }
        }

        /// <summary>
        /// 主题已更改
        /// </summary>
        public virtual void OnSkinChanged()
        {
            SkinManager.SyncSkinValueToProperty(this);
            this.Invalidate();
        }

        private ISkinObject followSkinObject = null;
        /// <summary>
        /// 主题设置跟随指定主题对象（自己的设置不再生效，提供给代码使用）
        /// </summary>
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [Localizable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual ISkinObject FollowSkinObject
        {
            get { return this.followSkinObject; }
            set
            {
                if (this.followSkinObject == value)
                    return;

                this.followSkinObject = value;
                this.OnSkinChanged();
            }
        }

        public virtual bool GetSkinObjectSkinStateCore()
        {
            return SkinManager.GetSkinObjectSkinState(this.FollowSkinObject ?? this);
        }

        void ISkinObject.InitializeInvalidate()
        {
            this.InitializeElement();
            this.Invalidate();
        }

        void ISkinObject.Invalidate()
        {
            this.Invalidate();
        }

        #endregion

        #region 停用事件

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler PaddingChanged
        {
            add { base.PaddingChanged += value; }
            remove { base.PaddingChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler BackgroundImageChanged
        {
            add { base.BackgroundImageChanged += value; }
            remove { base.BackgroundImageChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler BackgroundImageLayoutChanged
        {
            add { base.BackgroundImageLayoutChanged += value; }
            remove { base.BackgroundImageLayoutChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler TextChanged
        {
            add { base.TextChanged += value; }
            remove { base.TextChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler RightToLeftChanged
        {
            add { base.RightToLeftChanged += value; }
            remove { base.RightToLeftChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler BackColorChanged
        {
            add { base.BackColorChanged += value; }
            remove { base.BackColorChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler ForeColorChanged
        {
            add { base.ForeColorChanged += value; }
            remove { base.ForeColorChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler Click
        {
            add { base.Click += value; }
            remove { base.Click -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler DoubleClick
        {
            add { base.DoubleClick += value; }
            remove { base.DoubleClick -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event MouseEventHandler MouseClick
        {
            add { base.MouseClick += value; }
            remove { base.MouseClick -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event MouseEventHandler MouseDoubleClick
        {
            add { base.MouseDoubleClick += value; }
            remove { base.MouseDoubleClick -= value; }
        }

        #endregion

        #region 新增事件

        #region 选项卡栏

        public delegate void TabBarDrawBackgroundEventHandler(object sender, TabControlPlusTabBarDrawBackgroundEventArgs e);
        private static readonly object EventTabBarDrawBackground = new object();
        /// <summary>
        /// 选项卡栏背景绘制事件
        /// </summary>
        [Description("选项卡栏背景绘制事件")]
        [Category("杂项_选项卡栏")]
        public event TabBarDrawBackgroundEventHandler TabBarDrawBackground
        {
            add { Events.AddHandler(EventTabBarDrawBackground, value); }
            remove { Events.RemoveHandler(EventTabBarDrawBackground, value); }
        }

        #endregion

        #region 导航栏

        public delegate void NavigationButtonOperatingEventHandler(object sender, TabControlPlusNavigationButtonOperatingEventArgs e);
        private static readonly object EventNavigationButtonOperating = new object();
        /// <summary>
        /// 导航按钮点击时事件
        /// </summary>
        [Description("导航按钮点击时事件")]
        [Category("杂项_导航栏")]
        public event NavigationButtonOperatingEventHandler NavigationButtonOperating
        {
            add { Events.AddHandler(EventNavigationButtonOperating, value); }
            remove { Events.RemoveHandler(EventNavigationButtonOperating, value); }
        }

        public delegate void NavigationButtonOperatedEventHandler(object sender, TabControlPlusNavigationButtonOperatedEventArgs e);
        private static readonly object EventNavigationButtonOperated = new object();
        /// <summary>
        /// 导航按钮点击后事件
        /// </summary>
        [Description("导航按钮点击后事件")]
        [Category("杂项_导航栏")]
        public event NavigationButtonOperatedEventHandler NavigationButtonOperated
        {
            add { Events.AddHandler(EventNavigationButtonOperated, value); }
            remove { Events.RemoveHandler(EventNavigationButtonOperated, value); }
        }

        #endregion

        #region TabItem

        public delegate void TabItemOperatingEventHandler(object sender, TabControlPlusTabItemOperatingEventArgs e);
        public delegate void TabItemOperatedEventHandler(object sender, TabControlPlusTabItemOperatedEventArgs e);

        private static readonly object EventTabItemDeselecting = new object();
        /// <summary>
        /// TabItem取消选中事件
        /// </summary>
        [Description("TabItem取消选中事件")]
        [Category("杂项_选项")]
        public event TabItemOperatingEventHandler TabItemDeselecting
        {
            add { Events.AddHandler(EventTabItemDeselecting, value); }
            remove { Events.RemoveHandler(EventTabItemDeselecting, value); }
        }

        private static readonly object EventTabItemDeselected = new object();
        /// <summary>
        /// TabItem取消选后事件
        /// </summary>
        [Description("TabItem取消选后事件")]
        [Category("杂项_选项")]
        public event TabItemOperatedEventHandler TabItemDeselected
        {
            add { Events.AddHandler(EventTabItemDeselected, value); }
            remove { Events.RemoveHandler(EventTabItemDeselected, value); }
        }

        private static readonly object EventTabItemSelecting = new object();
        /// <summary>
        /// TabItem选中时事件
        /// </summary>
        [Description("TabItem选中时事件")]
        [Category("杂项_选项")]
        public event TabItemOperatingEventHandler TabItemSelecting
        {
            add { Events.AddHandler(EventTabItemSelecting, value); }
            remove { Events.RemoveHandler(EventTabItemSelecting, value); }
        }

        private static readonly object EventTabItemSelected = new object();
        /// <summary>
        /// TabItem选中后事件
        /// </summary>
        [Description("TabItem选中后事件")]
        [Category("杂项_选项")]
        public event TabItemOperatedEventHandler TabItemSelected
        {
            add { Events.AddHandler(EventTabItemSelected, value); }
            remove { Events.RemoveHandler(EventTabItemSelected, value); }
        }

        private static readonly object EventSelectedIndexChanged = new object();
        /// <summary>
        /// TabItem选中索引更改后事件
        /// </summary>
        [Description("TabItem选中索引更改后事件")]
        [Category("杂项_选项")]
        public event EventHandler SelectedIndexChanged
        {
            add { Events.AddHandler(EventSelectedIndexChanged, value); }
            remove { Events.RemoveHandler(EventSelectedIndexChanged, value); }
        }

        private static readonly object EventTabItemEnabledChanged = new object();
        /// <summary>
        /// TabItem启用状态更改事件
        /// </summary>
        [Description("TabItem启用状态更改事件")]
        [Category("杂项_选项")]
        public event TabItemOperatedEventHandler TabItemEnabledChanged
        {
            add { Events.AddHandler(EventTabItemEnabledChanged, value); }
            remove { Events.RemoveHandler(EventTabItemEnabledChanged, value); }
        }

        public delegate void TabItemInterchangeingEventHandler(object sender, TabControlPlusTabItemInterchangeingEventArgs e);
        private static readonly object EventTabItemInterchangeing = new object();
        /// <summary>
        /// 两个TabItem位置互换时事件
        /// </summary>
        [Description("两个TabItem位置互换时事件")]
        [Category("杂项_选项")]
        public event TabItemInterchangeingEventHandler TabItemInterchangeing
        {
            add { Events.AddHandler(EventTabItemInterchangeing, value); }
            remove { Events.RemoveHandler(EventTabItemInterchangeing, value); }
        }

        public delegate void TabItemInterchangedEventHandler(object sender, TabControlPlusTabItemInterchangedEventArgs e);
        private static readonly object EventTabItemInterchanged = new object();
        /// <summary>
        /// 两个TabItem位置互换后事件
        /// </summary>
        [Description("两个TabItem位置互换后事件")]
        [Category("杂项_选项")]
        public event TabItemInterchangedEventHandler TabItemInterchanged
        {
            add { Events.AddHandler(EventTabItemInterchanged, value); }
            remove { Events.RemoveHandler(EventTabItemInterchanged, value); }
        }

        public delegate void TabItemDrawBackgroundBeforeEventHandler(object sender, TabControlPlusTabItemDrawBackgroundBeforeEventArgs e);
        private static readonly object EventTabItemDrawBackgroundBefore = new object();
        /// <summary>
        /// TabItem背景绘制前事件
        /// </summary>
        [Description("TabItem背景绘制前事件")]
        [Category("杂项_选项")]
        public event TabItemDrawBackgroundBeforeEventHandler TabItemDrawBackgroundBefore
        {
            add { Events.AddHandler(EventTabItemDrawBackgroundBefore, value); }
            remove { Events.RemoveHandler(EventTabItemDrawBackgroundBefore, value); }
        }

        public delegate void TabItemDrawBackgroundAfterEventHandler(object sender, TabControlPlusTabItemDrawBackgroundAfterEventArgs e);
        private static readonly object EventTabItemDrawBackgroundAfter = new object();
        /// <summary>
        /// TabItem背景绘制后事件
        /// </summary>
        [Description("TabItem背景绘制后事件")]
        [Category("杂项_选项")]
        public event TabItemDrawBackgroundAfterEventHandler TabItemDrawBackgroundAfter
        {
            add { Events.AddHandler(EventTabItemDrawBackgroundAfter, value); }
            remove { Events.RemoveHandler(EventTabItemDrawBackgroundAfter, value); }
        }

        public delegate void TabItemCreateCustomPathBeforeEventHandler(object sender, TabControlPlusTabItemCreateCustomPathBeforeEventArgs e);
        private static readonly object EventTabItemCreateCustomPathBefore = new object();
        /// <summary>
        /// TabItem生成选项自定义路径事件
        /// </summary>
        [Description("TabItem生成选项自定义路径事件")]
        [Category("杂项_选项")]
        public event TabItemCreateCustomPathBeforeEventHandler TabItemCreateCustomPathBefore
        {
            add
            {
                Events.AddHandler(EventTabItemCreateCustomPathBefore, value);
                this.InitializeElement();
                this.Invalidate();
            }
            remove
            {
                Events.RemoveHandler(EventTabItemCreateCustomPathBefore, value);
                this.InitializeElement();
                this.Invalidate();
            }
        }

        #endregion

        #endregion

        #region 新增属性

        private TabBarObject tabBar;
        /// <summary>
        /// 选项卡栏
        /// </summary>
        [Description("选项卡栏")]
        [Category("杂项")]
        [PropertyOrder(-192)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public TabBarObject TabBar
        {
            get
            {
                if (this.tabBar == null)
                    this.tabBar = new TabBarObject(this);
                return this.tabBar;
            }
        }

        private int bodyBorderThickness = 1;
        /// <summary>
        /// 主体区域边框厚度
        /// </summary>
        [Description("主体区域边框厚度")]
        [Category("杂项")]
        [PropertyOrder(-191)]
        [DefaultValue(1)]
        public int BodyBorderThickness
        {
            get { return this.bodyBorderThickness; }
            set
            {
                if (this.bodyBorderThickness == value || value < 0)
                    return;

                this.bodyBorderThickness = value;
                this.InitializeElement();
                this.Invalidate();
            }
        }

        private PickerObject picker;
        /// <summary>
        /// 下拉面板
        /// </summary>
        [Description("下拉面板")]
        [Category("杂项")]
        [PropertyOrder(-186)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public PickerObject Picker
        {
            get
            {
                if (this.picker == null)
                    this.picker = new PickerObject(this);
                return this.picker;
            }
        }

        private TabPagePlusCollection tabPagePlusCollection;
        /// <summary>
        /// TabPage集合
        /// </summary>
        [Description("TabPage集合")]
        [Category("杂项")]
        [PropertyOrder(-100)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public TabPagePlusCollection TabPages
        {
            get
            {
                if (this.tabPagePlusCollection == null)
                    this.tabPagePlusCollection = new TabPagePlusCollection(this);
                return this.tabPagePlusCollection;
            }
        }

        /// <summary>
        /// TabPage总数
        /// </summary>
        [Description("TabPage总数")]
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int TabCount
        {
            get { return this.tabPages.Count(); }
        }

        private int selectedIndex = -1;
        /// <summary>
        /// 已选中TabPage索引
        /// </summary>
        [Description("已选中TabPage索引")]
        [DefaultValue("-1")]
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int SelectedIndex
        {
            get { return this.selectedIndex; }
            set
            {
                if (this.selectedIndex == value || value < -1 || value >= this.TabCount)
                    return;

                int old_tabPageIndex = this.selectedIndex;
                TabPagePlus old_tabPage = this.GetTabPage(this.selectedIndex);
                if (old_tabPage != null)
                {
                    //旧已选中选项取消中事件
                    TabControlPlusTabItemOperatingEventArgs deselecting_arg = new TabControlPlusTabItemOperatingEventArgs(old_tabPage, false);
                    this.OnTabItemDeselecting(deselecting_arg);
                    if (deselecting_arg.Cancel)
                    {
                        return;
                    }

                    //旧已选中选项取消后事件
                    TabControlPlusTabItemOperatedEventArgs deselected_arg = new TabControlPlusTabItemOperatedEventArgs(old_tabPage);
                    this.OnTabItemDeselected(deselected_arg);
                }

                this.selectedIndex = value;
                TabPagePlus new_tabPage = this.GetTabPage(this.selectedIndex);
                if (new_tabPage != null)
                {
                    // 新选项选中中事件
                    TabControlPlusTabItemOperatingEventArgs selecting_arg = new TabControlPlusTabItemOperatingEventArgs(new_tabPage, false);
                    this.OnTabItemSelecting(selecting_arg);
                    if (selecting_arg.Cancel)
                    {
                        this.selectedIndex = old_tabPageIndex;
                        return;
                    }

                    // 新选项选中后事件
                    TabControlPlusTabItemOperatedEventArgs selected_arg = new TabControlPlusTabItemOperatedEventArgs(new_tabPage);
                    this.OnTabItemSelected(selected_arg);
                }

                //选中索引更改事件
                this.OnSelectedIndexChanged(new TabControlPlusTabItemOperatedEventArgs(this.SelectedTab));

                //更新画面信息
                this.ReplenishSelectTabItemToRectangle();
                this.ReplenishTabItemToRectangleForLeft();
                this.Invalidate();

                this.SetActiveTabPage(this.selectedIndex);
                this.UpdateTabSelection();
            }
        }

        /// <summary>
        /// 已选中TabPage
        /// </summary>
        [Description("已选中TabPage")]
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public TabPagePlus SelectedTab
        {
            get
            {
                if (this.SelectedIndex < 0 || this.SelectedIndex >= this.TabCount)
                    return null;

                return this.TabPages[this.SelectedIndex];
            }
            set
            {
                int index = this.FindTabPage(value);

                if (this.selectedIndex < 0 || this.selectedIndex >= this.TabCount)
                    return;

                this.SelectedIndex = index;
            }
        }


        /// <summary>
        /// 在tabitem显示的总区域中要显示的第一个tabitem的索引
        /// </summary>
        [Description("在tabitem显示的总区域中要显示的第一个tabitem的索引")]
        [Category("杂项_选项")]
        [PropertyOrder(-151)]
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int FirstIndex
        {
            get { return this.tabbar_items_start_index; }
        }


        #endregion

        #region 重写属性

        protected override Size DefaultSize
        {
            get { return new Size(300, 150); }
        }

        [DefaultValue(typeof(Padding), "0")]
        protected override Padding DefaultPadding
        {
            get { return new Padding(0); }
        }

        public override Font Font
        {
            get { return base.Font; }
            set
            {
                if (base.Font == value)
                    return;

                base.Font = value;
                this.InitializeElement();
                this.Invalidate();
            }
        }

        #endregion

        #region 停用属性

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public new Padding Padding
        {
            get { return base.Padding; }
            set { base.Padding = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new Image BackgroundImage
        {
            get { return base.BackgroundImage; }
            set { base.BackgroundImage = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new ImageLayout BackgroundImageLayout
        {
            get { return base.BackgroundImageLayout; }
            set { base.BackgroundImageLayout = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override string Text
        {
            get { return base.Text; }
            set { base.Text = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public override RightToLeft RightToLeft
        {
            get { return base.RightToLeft; }
            set { base.RightToLeft = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override Color BackColor
        {
            get { return this.StyleAppearance.BackColor; }
            set { }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override Color ForeColor
        {
            get { return this.StyleAppearance.TabBar.TabItem.Normal.TextColor; }
            set { }
        }

        #endregion

        #region 字段

        /// <summary>
        /// 选项卡栏rect(包含：内边距、内容)
        /// </summary>
        private Rectangle tabbar_p_rect = new Rectangle();

        /// <summary>
        /// 选项卡栏rect(包含：内容)
        /// </summary>
        private Rectangle tabbar_c_rect = new Rectangle();

        /// <summary>
        /// 全局按钮rect(包含：内容)
        /// </summary>
        private Rectangle tabbar_globalbuttton_c_rect = new Rectangle();

        /// <summary>
        /// 导航栏rect(包含：内容)
        /// </summary>
        private Rectangle tabbar_navigationbar_c_rect = new Rectangle();

        /// <summary>
        /// tabitem显示的总区域(选项卡栏rect减去全局按钮rect减去导航栏rect)
        /// </summary>
        private Rectangle tabbar_items_c_rect = new Rectangle();

        /// <summary>
        /// 主体区域(包含：内容)
        /// </summary>
        private Rectangle body_c_rect = new Rectangle();

        /// <summary>
        /// 在tabitem显示的总区域中要显示的第一个tabitem的索引
        /// </summary>
        private int tabbar_items_start_index = 0;

        /// <summary>
        /// 视觉上当前导航栏是否显示
        /// </summary>
        private bool tabbar_navigationbar_visualstatus = false;

        /// <summary>
        /// 用于存放TabPage数组
        /// </summary>
        private TabPagePlus[] tabPages = new TabPagePlus[0];

        /// <summary>
        /// 鼠标已按下的对象
        /// </summary>
        private object mousedownobject = null;
        /// <summary>
        /// 鼠标已进入的对象
        /// </summary>
        private object mouseenterobject = null;
        /// <summary>
        /// 鼠标已进入的对象子选项
        /// </summary>
        private object mouseenterobjectchildren = null;
        /// <summary>
        /// 鼠标已进入要提示的对象
        /// </summary>
        private object mouseenterobjecttip = null;

        /// <summary>
        /// 提示信息弹层
        /// </summary>
        private static ToolTipPlus ttp;

        /// <summary>
        /// 提示信息弹层拥有者
        /// </summary>
        private static TabControlPlus ttp_owner = null;

        /// <summary>
        /// 下拉面板
        /// </summary>
        private TabControlPlusPicker pickerObject = null;

        /// <summary>
        /// 下拉面板浮层
        /// </summary>
        private ToolStripDropDown tsdd = null;

        /// <summary>
        /// 下拉面板浮层容器
        /// </summary>
        private ToolStripControlHost tsch = null;

        #endregion

        public TabControlPlus()
        {
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.ResizeRedraw, true);
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            SetStyle(ControlStyles.StandardClick, false);//自定义单击事件逻辑
            SetStyle(ControlStyles.StandardDoubleClick, false);//停用双加事件

            this.InitializeElement();
            this.OnSkinChanged();

        }

        #region 重写

        protected override void OnScaleDpiChangedInitialize()
        {
            this.InitializeElement();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Graphics g = e.Graphics;

            // 绘制选项卡栏背景
            this.DrawTabBarBackground(g);

            Region tabbar_clipbounds_c_region = new Region(this.tabbar_c_rect);
            g.Clip = tabbar_clipbounds_c_region;

            // 绘制全局按钮
            this.DrawGlobalButttons(g);
            // 绘制导航栏
            this.DrawNavigationBar(g);
            // 绘制选项
            this.DrawTabItem(g);
            // 绘制主体区域
            this.DrawBody(g);

            tabbar_clipbounds_c_region.Dispose();
        }

        protected override void OnGotFocus(EventArgs e)
        {
            base.OnGotFocus(e);

            this.mousedownobject = null;
            this.mouseenterobject = null;
            this.mouseenterobjectchildren = null;
            this.mouseenterobjecttip = null;
            this.Invalidate();
        }

        protected override void OnLostFocus(EventArgs e)
        {
            base.OnLostFocus(e);

            this.mousedownobject = null;
            this.mouseenterobject = null;
            this.mouseenterobjectchildren = null;
            this.mouseenterobjecttip = null;
            this.Invalidate();
            this.TipHide();
        }

        protected override void OnEnabledChanged(EventArgs e)
        {
            base.OnEnabledChanged(e);

            if (!this.Enabled)
            {
                this.mousedownobject = null;
                this.mouseenterobject = null;
                this.mouseenterobjectchildren = null;
                this.mouseenterobjecttip = null;
                this.Invalidate();
                this.TipHide();
            }
        }

        protected override void OnVisibleChanged(EventArgs e)
        {
            base.OnVisibleChanged(e);

            if (!this.Visible)
            {
                this.mousedownobject = null;
                this.mouseenterobject = null;
                this.mouseenterobjectchildren = null;
                this.mouseenterobjecttip = null;
                this.Invalidate();
                this.TipHide();
            }
        }

        protected override void OnParentChanged(EventArgs e)
        {
            base.OnParentChanged(e);

            if (this.Parent == null)
            {
                this.mousedownobject = null;
                this.mouseenterobject = null;
                this.mouseenterobjectchildren = null;
                this.mouseenterobjecttip = null;
                this.Invalidate();
                this.TipHide();
            }
        }

        protected override void OnMouseEnter(EventArgs e)
        {
            base.OnMouseEnter(e);

            Point point = this.PointToClient(Control.MousePosition);
            object mouseenterobject_tmp = null;
            object mouseenterobjectchildren_tmp = null;
            object mouseenterobjecttip_tmp = null;

            if (this.tabbar_items_c_rect.Contains(point))
            {
                for (int i = 0; i < this.TabPages.Count; i++)
                {
                    TabPagePlus teb_page = this.TabPages[i];
                    if (teb_page.TabItem.Enabled && teb_page.P_GP.IsVisible(point))
                    {
                        mouseenterobject_tmp = teb_page;
                        // 关闭
                        if (!this.DesignMode && this.GetProperty_ItemColseVisible(teb_page) && teb_page.TabItem.CloseButton.Enabled && teb_page.TabItem.CloseButton.C_Rect.Contains(point))
                        {
                            mouseenterobjectchildren_tmp = teb_page.TabItem.CloseButton;
                            goto result;
                        }
                        foreach (TabControlPlusTabItemCustomButton item in teb_page.TabItem.CustomButtons)
                        {
                            if (!this.DesignMode && item.Enabled && item.Visible && item.C_Rect.Contains(point))
                            {
                                mouseenterobjectchildren_tmp = item;
                                mouseenterobjecttip_tmp = item;
                                goto result;
                            }
                        }
                        goto result;
                    }
                }
            }
            if (this.TabBar.NavigationBar.Visible && this.tabbar_navigationbar_visualstatus && this.TabBar.NavigationBar.PrevButton.C_Rect.Contains(point))
            {
                mouseenterobject_tmp = this.TabBar.NavigationBar.PrevButton;
                goto result;
            }
            if (this.TabBar.NavigationBar.Visible && this.tabbar_navigationbar_visualstatus && this.TabBar.NavigationBar.NextButton.C_Rect.Contains(point))
            {
                mouseenterobject_tmp = this.TabBar.NavigationBar.NextButton;
                goto result;
            }
            if (this.TabBar.GlobalButttons.Count > 0 && this.tabbar_globalbuttton_c_rect.Contains(point))
            {
                for (int i = 0; i < this.TabBar.GlobalButttons.Count; i++)
                {
                    TabControlPlusGlobalButtton btn = this.TabBar.GlobalButttons[i];
                    if (btn.Visible && btn.C_Rect.Contains(point))
                    {
                        mouseenterobject_tmp = btn;
                        mouseenterobjecttip_tmp = btn;
                        goto result;
                    }
                }
            }

        result:
            {
                if (this.mouseenterobject != mouseenterobject_tmp || this.mouseenterobjectchildren != mouseenterobjectchildren_tmp)
                {
                    this.mouseenterobject = mouseenterobject_tmp;
                    this.mouseenterobjectchildren = mouseenterobjectchildren_tmp;
                    this.Invalidate();
                }
                if (this.mouseenterobjecttip != mouseenterobjecttip_tmp)
                {
                    this.mouseenterobjecttip = mouseenterobjecttip_tmp;
                    if (this.mouseenterobjecttip == null)
                    {
                        this.TipHide();
                    }
                    else
                    {
                        this.TipShow(this.mouseenterobjecttip);
                    }
                }
            }
        }

        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);

            this.mouseenterobject = null;
            this.mouseenterobjectchildren = null;
            this.mouseenterobjecttip = null;
            this.Invalidate();
            this.TipHide();
        }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            if (!this.Focused)
            {
                this.Focus();
            }

            // 检查当前鼠标按下的对象
            if (e.Button == MouseButtons.Left)
            {
                Point point = e.Location;

                if (this.tabbar_c_rect.Contains(point) == false)
                {
                    this.mousedownobject = null;
                    return;
                }

                bool isfind = false;

                //全局按钮
                if (!isfind)
                {
                    if (this.GetGlobalButttonVisualstatus() && this.tabbar_globalbuttton_c_rect.Contains(point))
                    {
                        if (this.DesignMode)
                        {
                            isfind = true;
                            this.mousedownobject = null;
                        }
                        else
                        {
                            for (int i = 0; i < this.TabBar.GlobalButttons.Count; i++)
                            {
                                TabControlPlusGlobalButtton btn = this.TabBar.GlobalButttons[i];
                                if (btn.Visible && btn.Enabled && btn.C_Rect.Contains(point))
                                {
                                    isfind = true;
                                    this.mousedownobject = btn;
                                    goto result;
                                }
                            }
                        }

                    result:
                        if (isfind == false && this.mousedownobject != null)
                        {
                            this.mousedownobject = null;
                        }
                    }
                }

                //导航栏
                if (!isfind)
                {
                    if (this.TabBar.NavigationBar.Visible && this.tabbar_navigationbar_visualstatus && this.tabbar_navigationbar_c_rect.Contains(point))
                    {
                        //上一页
                        if (this.TabBar.NavigationBar.PrevButton.C_Rect.Contains(point))
                        {
                            isfind = true;
                            this.mousedownobject = this.TabBar.NavigationBar.PrevButton;
                            goto result;
                        }
                        //下一页
                        if (this.TabBar.NavigationBar.NextButton.C_Rect.Contains(point))
                        {
                            isfind = true;
                            this.mousedownobject = this.TabBar.NavigationBar.NextButton;
                            goto result;
                        }

                    result:
                        if (isfind == false && this.mousedownobject != null)
                        {
                            this.mousedownobject = null;
                        }
                    }
                }

                //所有选项、选项自定义按钮、选项关闭按钮
                if (!isfind)
                {
                    if (this.DesignMode)
                    {
                        if (this.tabbar_items_c_rect.Contains(point))
                        {
                            for (int i = 0; i < this.TabCount; i++)
                            {
                                if (this.TabPages[i].P_GP.IsVisible(point))
                                {
                                    isfind = true;
                                    this.mousedownobject = this.TabPages[i];
                                    goto result;
                                }
                            }

                        result:
                            if (isfind == false && this.mousedownobject != null)
                            {
                                this.mousedownobject = null;
                            }
                        }
                    }
                    else
                    {
                        if (this.tabbar_items_c_rect.Contains(point))
                        {
                            for (int i = 0; i < this.TabCount; i++)
                            {
                                if (this.TabPages[i].P_GP.IsVisible(point))
                                {
                                    if (this.TabPages[i].TabItem.Enabled)
                                    {
                                        //自定义按钮
                                        foreach (TabControlPlusTabItemCustomButton btn in this.TabPages[i].TabItem.CustomButtons)
                                        {
                                            if (btn.Visible && btn.Enabled && btn.C_Rect.Contains(point))
                                            {
                                                isfind = true;
                                                this.mousedownobject = btn;
                                                goto result;
                                            }
                                        }

                                        //关闭按钮
                                        if (this.GetProperty_ItemColseVisible(this.tabPages[i]) && this.TabPages[i].TabItem.CloseButton.Enabled && this.TabPages[i].TabItem.CloseButton.C_Rect.Contains(point))
                                        {
                                            isfind = true;
                                            this.mousedownobject = this.TabPages[i].TabItem.CloseButton;
                                            goto result;
                                        }

                                        isfind = true;
                                        this.mousedownobject = this.TabPages[i];
                                        goto result;
                                    }
                                    else
                                    {
                                        if (this.TabBar.TabItem.DisableActivation)
                                        {
                                            this.mousedownobject = this.TabPages[i];
                                        }
                                    }

                                    isfind = true;
                                    goto result;
                                }

                            }

                        result:
                            if (isfind == false && this.mousedownobject != null)
                            {
                                this.mousedownobject = null;
                            }
                        }
                    }
                }
            }


            base.OnMouseDown(e);
        }

        protected override void OnMouseUp(MouseEventArgs e)
        {
            // 检查当前鼠标释放的对象
            if (e.Button == MouseButtons.Left)
            {
                Point point = e.Location;

                if (this.tabbar_c_rect.Contains(point) == false)
                {
                    this.mousedownobject = null;
                    return;
                }

                bool isfind = false;

                //判断是否单击全局按钮
                if (!isfind)
                {
                    if (this.GetGlobalButttonVisualstatus() && this.tabbar_globalbuttton_c_rect.Contains(point))
                    {
                        if (this.DesignMode == false)
                        {
                            for (int i = 0; i < this.TabBar.GlobalButttons.Count; i++)
                            {
                                TabControlPlusGlobalButtton btn = this.TabBar.GlobalButttons[i];
                                if (btn.C_Rect.Contains(point))
                                {
                                    if (this.mousedownobject == btn && btn.Enabled)
                                    {
                                        btn.OnGlobalButttonClick(new TabControlPlusGlobalButttonEventArgs(btn));
                                    }
                                    isfind = true;
                                    goto restlt;
                                }
                            }
                        }

                        isfind = true;
                        goto restlt;
                    }

                restlt:
                    { }
                }


                // 判断是否单击导航栏按钮
                if (!isfind)
                {
                    if (this.TabBar.NavigationBar.Visible && this.tabbar_navigationbar_visualstatus && this.tabbar_navigationbar_c_rect.Contains(point))
                    {
                        //上一页
                        if (this.TabBar.NavigationBar.PrevButton.C_Rect.Contains(point))
                        {
                            if (this.mousedownobject == this.TabBar.NavigationBar.PrevButton)
                            {
                                int index = this.tabbar_items_start_index - 1;
                                if (index < 0)
                                {
                                    index = 0;
                                }

                                if (this.tabbar_items_start_index != index)
                                {
                                    TabControlPlusNavigationButtonOperatingEventArgs arg = new TabControlPlusNavigationButtonOperatingEventArgs(false, this.tabbar_items_start_index, index, false);
                                    this.OnNavigationButtonOperating(arg);
                                    if (arg.Cancel == false)
                                    {
                                        this.tabbar_items_start_index = index;

                                        this.UpdateEveryOneTabItemRectangle();
                                        this.Invalidate();

                                        this.OnNavigationButtonOperated(new TabControlPlusNavigationButtonOperatedEventArgs(false, this.tabbar_items_start_index));
                                    }
                                }
                            }
                            isfind = true;
                            goto restlt;
                        }
                        //下一页
                        if (this.TabBar.NavigationBar.NextButton.C_Rect.Contains(point))
                        {
                            if (this.mousedownobject == this.TabBar.NavigationBar.NextButton)
                            {
                                bool isreset = false;
                                if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Top || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Bottom)
                                {
                                    if (this.TabCount > 0 && this.TabPages[this.TabCount - 1].P_Rect.Right > this.tabbar_items_c_rect.Right)
                                    {
                                        isreset = true;
                                    }
                                }
                                else
                                {
                                    if (this.TabCount > 0 && this.TabPages[this.TabCount - 1].P_Rect.Bottom >= this.tabbar_items_c_rect.Bottom)
                                    {
                                        isreset = true;
                                    }
                                }

                                if (isreset)
                                {
                                    int index = this.tabbar_items_start_index + 1;
                                    if (index >= this.TabCount)
                                    {
                                        index = this.TabCount - 1;
                                    }
                                    if (this.tabbar_items_start_index != index)
                                    {
                                        TabControlPlusNavigationButtonOperatingEventArgs arg = new TabControlPlusNavigationButtonOperatingEventArgs(true, this.tabbar_items_start_index, index, false);
                                        this.OnNavigationButtonOperating(arg);
                                        if (arg.Cancel == false)
                                        {
                                            this.tabbar_items_start_index = index;

                                            this.UpdateEveryOneTabItemRectangle();
                                            this.Invalidate();

                                            this.OnNavigationButtonOperated(new TabControlPlusNavigationButtonOperatedEventArgs(true, this.tabbar_items_start_index));

                                        }
                                    }
                                }
                            }
                            isfind = true;
                            goto restlt;
                        }

                        isfind = true;
                        goto restlt;
                    }

                restlt:
                    { }
                }

                // 判断是否单击TabItem选项
                if (!isfind)
                {
                    if (this.DesignMode)
                    {
                        if (this.tabbar_items_c_rect.Contains(point))
                        {
                            for (int i = 0; i < this.TabCount; i++)
                            {
                                if (this.TabPages[i].P_GP.IsVisible(point))
                                {
                                    if (this.mousedownobject == this.TabPages[i])
                                    {
                                        this.SelectedIndex = i;
                                    }
                                    isfind = true;
                                    goto result;
                                }
                            }

                            isfind = true;
                            goto result;
                        }
                    }
                    else
                    {
                        if (this.tabbar_items_c_rect.Contains(point))
                        {
                            for (int i = 0; i < this.TabCount; i++)
                            {
                                TabPagePlus tab_page = this.TabPages[i];
                                if (tab_page.P_GP.IsVisible(point))
                                {
                                    if (tab_page.TabItem.Enabled)
                                    {
                                        //自定义按钮
                                        foreach (TabControlPlusTabItemCustomButton btn in tab_page.TabItem.CustomButtons)
                                        {
                                            if (btn.Visible && btn.C_Rect.Contains(point))
                                            {
                                                if (this.mousedownobject == btn && btn.Enabled)
                                                {
                                                    if (btn.CheckButton)
                                                    {
                                                        btn.Checked = !btn.Checked;
                                                    }
                                                    else
                                                    {
                                                        btn.OnTabItemCustomButtonClick(new TabControlPlusTabItemCustomButttonOperatedEventArgs(tab_page, btn));
                                                    }
                                                }
                                                isfind = true;
                                                goto result;
                                            }
                                        }

                                        //关闭按钮
                                        if (this.GetProperty_ItemColseVisible(tab_page) && tab_page.TabItem.CloseButton.C_Rect.Contains(point))
                                        {
                                            if (this.mousedownobject == tab_page.TabItem.CloseButton && tab_page.TabItem.CloseButton.Enabled)
                                            {
                                                TabControlPlusTabItemCloseButtonCloseingEventArgs arg = new TabControlPlusTabItemCloseButtonCloseingEventArgs(tab_page, false);
                                                tab_page.OnTabItemCloseButtonCloseing(arg);
                                                if (arg.Cancel == false)
                                                {
                                                    this.RemoveTabPage(i);

                                                    tab_page.OnTabItemCloseButtonClosed(new TabControlPlusTabItemCloseButtonClosedEventArgs(tab_page));
                                                }
                                            }

                                            isfind = true;
                                            goto result;
                                        }

                                        //选项选中
                                        if (this.mousedownobject == tab_page)
                                        {
                                            this.SelectedIndex = i;
                                        }
                                        else
                                        {
                                            //选项移动
                                            if (this.TabBar.TabItem.InterchangeEnabled && this.mousedownobject != null)
                                            {
                                                TabPagePlus current_tabpage_tmp = (TabPagePlus)this.mousedownobject;
                                                //TabItem索引更改时事件
                                                TabControlPlusTabItemInterchangeingEventArgs changeing_arg = new TabControlPlusTabItemInterchangeingEventArgs(current_tabpage_tmp, tab_page, false);
                                                this.OnTabItemInterchangeing(changeing_arg);
                                                if (changeing_arg.Cancel)
                                                {
                                                    isfind = true;
                                                    goto result;
                                                }

                                                this.InterchangeTabItemIndex(current_tabpage_tmp, tab_page);

                                                //TabItem索引更改后事件
                                                TabControlPlusTabItemInterchangedEventArgs changed_arg = new TabControlPlusTabItemInterchangedEventArgs(current_tabpage_tmp, tab_page);
                                                this.OnTabItemInterchanged(changed_arg);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        //选项选中
                                        if (this.mousedownobject == tab_page)
                                        {
                                            if (this.TabBar.TabItem.DisableActivation)
                                            {
                                                this.SelectedIndex = i;
                                            }
                                        }
                                        else
                                        {
                                            //选项移动
                                            if (this.TabBar.TabItem.InterchangeEnabled && this.mousedownobject != null)
                                            {
                                                TabPagePlus current_tabpage_tmp = (TabPagePlus)this.mousedownobject;
                                                //TabItem索引更改时事件
                                                TabControlPlusTabItemInterchangeingEventArgs changeing_arg = new TabControlPlusTabItemInterchangeingEventArgs(current_tabpage_tmp, tab_page, false);
                                                this.OnTabItemInterchangeing(changeing_arg);
                                                if (changeing_arg.Cancel)
                                                {
                                                    isfind = true;
                                                    goto result;
                                                }

                                                this.InterchangeTabItemIndex(current_tabpage_tmp, tab_page);

                                                //TabItem索引更改后事件
                                                TabControlPlusTabItemInterchangedEventArgs changed_arg = new TabControlPlusTabItemInterchangedEventArgs(current_tabpage_tmp, tab_page);
                                                this.OnTabItemInterchanged(changed_arg);
                                            }
                                        }
                                    }

                                    isfind = true;
                                    goto result;
                                }
                            }

                            isfind = true;
                            goto result;
                        }
                    }

                result:
                    { }
                }

            }

            this.mousedownobject = null;

            base.OnMouseUp(e);
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (this.mousedownobject == null)
            {
                object mouseenterobject_tmp = null;
                object mouseenterobjectchildren_tmp = null;
                object mouseenterobjecttip_tmp = null;

                if (this.tabbar_items_c_rect.Contains(e.Location))
                {
                    for (int i = 0; i < this.TabPages.Count; i++)
                    {
                        TabPagePlus teb_page = this.TabPages[i];
                        if (teb_page.TabItem.Enabled && teb_page.P_GP.IsVisible(e.Location))
                        {
                            mouseenterobject_tmp = teb_page;
                            // 关闭
                            if (!this.DesignMode && this.GetProperty_ItemColseVisible(teb_page) && teb_page.TabItem.CloseButton.Enabled && teb_page.TabItem.CloseButton.C_Rect.Contains(e.Location))
                            {
                                mouseenterobjectchildren_tmp = teb_page.TabItem.CloseButton;
                                goto result;
                            }
                            foreach (TabControlPlusTabItemCustomButton item in teb_page.TabItem.CustomButtons)
                            {
                                if (!this.DesignMode && item.Enabled && item.Visible && item.C_Rect.Contains(e.Location))
                                {
                                    mouseenterobjectchildren_tmp = item;
                                    mouseenterobjecttip_tmp = item;
                                    goto result;
                                }
                            }
                            goto result;
                        }
                    }
                }
                if (this.TabBar.NavigationBar.Visible && this.tabbar_navigationbar_visualstatus && this.TabBar.NavigationBar.PrevButton.C_Rect.Contains(e.Location))
                {
                    mouseenterobject_tmp = this.TabBar.NavigationBar.PrevButton;
                    goto result;
                }
                if (this.TabBar.NavigationBar.Visible && this.tabbar_navigationbar_visualstatus && this.TabBar.NavigationBar.NextButton.C_Rect.Contains(e.Location))
                {
                    mouseenterobject_tmp = this.TabBar.NavigationBar.NextButton;
                    goto result;
                }
                if (this.TabBar.GlobalButttons.Count > 0 && this.tabbar_globalbuttton_c_rect.Contains(e.Location))
                {
                    for (int i = 0; i < this.TabBar.GlobalButttons.Count; i++)
                    {
                        TabControlPlusGlobalButtton btn = this.TabBar.GlobalButttons[i];
                        if (btn.Visible && btn.C_Rect.Contains(e.Location))
                        {
                            mouseenterobject_tmp = btn;
                            mouseenterobjecttip_tmp = btn;
                            goto result;
                        }
                    }
                }

            result:
                {
                    if (this.mouseenterobject != mouseenterobject_tmp || this.mouseenterobjectchildren != mouseenterobjectchildren_tmp)
                    {
                        this.mouseenterobject = mouseenterobject_tmp;
                        this.mouseenterobjectchildren = mouseenterobjectchildren_tmp;
                        this.Invalidate();
                    }
                    if (this.mouseenterobjecttip != mouseenterobjecttip_tmp)
                    {
                        this.mouseenterobjecttip = mouseenterobjecttip_tmp;
                        if (this.mouseenterobjecttip == null)
                        {
                            this.TipHide();
                        }
                        else
                        {
                            this.TipShow(this.mouseenterobjecttip);
                        }
                    }
                }

            }

        }

        protected override bool ProcessDialogKey(Keys keyData)
        {
            switch (keyData)
            {
                case Keys.Up:
                case Keys.Down:
                    {
                        if (!this.Focused)
                            break;

                        return true;
                    }
                case Keys.Left:
                    {
                        if (!this.Focused)
                            break;

                        if (this.TabCount > 0)
                        {
                            if (this.DesignMode || this.TabBar.TabItem.DisableActivation)
                            {
                                this.SelectedIndex = Math.Max(0, this.SelectedIndex - 1);
                            }
                            else
                            {
                                for (int i = this.SelectedIndex - 1; i >= 0; i--)
                                {
                                    if (this.TabPages[i].TabItem.Enabled)
                                    {
                                        this.SelectedIndex = i;
                                        break;
                                    }
                                }
                            }
                        }
                        return true;
                    }
                case Keys.Right:
                    {
                        if (!this.Focused)
                            break;

                        if (this.TabCount > 0)
                        {
                            if (this.DesignMode || this.TabBar.TabItem.DisableActivation)
                            {
                                this.SelectedIndex = Math.Min(this.TabCount - 1, this.SelectedIndex + 1);
                            }
                            else
                            {
                                for (int i = this.SelectedIndex + 1; i < this.TabCount; i++)
                                {
                                    if (this.TabPages[i].TabItem.Enabled)
                                    {
                                        this.SelectedIndex = i;
                                        break;
                                    }
                                }
                            }
                        }
                        return true;
                    }
                case Keys.Tab:
                    {
                        //this.GetNextControl(this,false
                        break;
                    }
            }

            return base.ProcessDialogKey(keyData);
        }

        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);

            this.UpdateTabBarRectangle();
            this.UpdateEveryOneTabItemRectangle();
            this.ReplenishSelectTabItemToRectangle();
            this.ReplenishTabItemToRectangleForLeft();
            this.ReplenishSelectTabItemToRectangle();
            this.UpdateTabMainDisplayRectangleByTabItemsDisplayRectangle();
            this.Invalidate();
        }

        protected override ControlCollection CreateControlsInstance()
        {
            return new TabControlPlusControlsCollection(this);
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                for (int i = 0; i < this.TabCount; i++)
                {
                    TabPagePlus tab_page = this.TabPages[i];
                    if (tab_page != null)
                    {
                        tab_page.Dispose();
                    }
                }
            }

            base.Dispose(disposing);
        }

        #endregion

        #region 虚方法

        //选项卡栏背景
        protected virtual void OnTabBarDrawBackground(TabControlPlusTabBarDrawBackgroundEventArgs e)
        {
            TabBarDrawBackgroundEventHandler handler = Events[EventTabBarDrawBackground] as TabBarDrawBackgroundEventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        //导航栏
        protected virtual void OnNavigationButtonOperating(TabControlPlusNavigationButtonOperatingEventArgs e)
        {
            NavigationButtonOperatingEventHandler handler = Events[EventNavigationButtonOperating] as NavigationButtonOperatingEventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected virtual void OnNavigationButtonOperated(TabControlPlusNavigationButtonOperatedEventArgs e)
        {
            NavigationButtonOperatedEventHandler handler = Events[EventNavigationButtonOperated] as NavigationButtonOperatedEventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        //TabItem
        protected virtual void OnTabItemDeselecting(TabControlPlusTabItemOperatingEventArgs e)
        {
            TabItemOperatingEventHandler handler = Events[EventTabItemDeselecting] as TabItemOperatingEventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected virtual void OnTabItemDeselected(TabControlPlusTabItemOperatedEventArgs e)
        {
            TabItemOperatedEventHandler handler = Events[EventTabItemDeselected] as TabItemOperatedEventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected virtual void OnTabItemSelecting(TabControlPlusTabItemOperatingEventArgs e)
        {
            TabItemOperatingEventHandler handler = Events[EventTabItemSelecting] as TabItemOperatingEventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected virtual void OnTabItemSelected(TabControlPlusTabItemOperatedEventArgs e)
        {
            TabItemOperatedEventHandler handler = Events[EventTabItemSelected] as TabItemOperatedEventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected virtual void OnSelectedIndexChanged(EventArgs e)
        {
            EventHandler handler = Events[EventSelectedIndexChanged] as EventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        internal protected virtual void OnTabItemEnabledChanged(TabControlPlusTabItemOperatedEventArgs e)
        {
            TabItemOperatedEventHandler handler = Events[EventTabItemEnabledChanged] as TabItemOperatedEventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected virtual void OnTabItemInterchangeing(TabControlPlusTabItemInterchangeingEventArgs e)
        {
            TabItemInterchangeingEventHandler handler = Events[EventTabItemInterchangeing] as TabItemInterchangeingEventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected virtual void OnTabItemInterchanged(TabControlPlusTabItemInterchangedEventArgs e)
        {
            TabItemInterchangedEventHandler handler = Events[EventTabItemInterchanged] as TabItemInterchangedEventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected virtual void OnTabItemDrawBackgroundBefore(TabControlPlusTabItemDrawBackgroundBeforeEventArgs e)
        {
            TabItemDrawBackgroundBeforeEventHandler handler = Events[EventTabItemDrawBackgroundBefore] as TabItemDrawBackgroundBeforeEventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected virtual void OnTabItemDrawBackgroundAfter(TabControlPlusTabItemDrawBackgroundAfterEventArgs e)
        {
            TabItemDrawBackgroundAfterEventHandler handler = Events[EventTabItemDrawBackgroundAfter] as TabItemDrawBackgroundAfterEventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected virtual void OnTabItemCreateCustomPathBefore(TabControlPlusTabItemCreateCustomPathBeforeEventArgs e)
        {
            TabItemCreateCustomPathBeforeEventHandler handler = Events[EventTabItemCreateCustomPathBefore] as TabItemCreateCustomPathBeforeEventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        #endregion

        #region 公开方法

        /// <summary>
        /// 初始化控件内部元素布局
        /// </summary>
        public void InitializeElement()
        {
            this.UpdateEveryOneTabItemSize();
            this.UpdateTabBarRectangle();
            this.UpdateEveryOneTabItemRectangle();

            this.ReplenishTabItemToRectangleForLeft();
            this.ReplenishSelectTabItemToRectangle();

            this.UpdateTabMainDisplayRectangleByTabItemsDisplayRectangle();
        }

        /// <summary>
        /// 尾部添加TabPage页
        /// </summary>
        /// <param name="tabPage">要添加的TabPage</param>
        /// <returns></returns>
        internal int AddTabPage(TabPagePlus tabPage)
        {
            int index = this.TabCount;
            this.Insert(this.TabCount, tabPage);
            return index;
        }

        /// <summary>
        /// 添加TabPage到指定索引位置
        /// </summary>
        /// <param name="index">指定索引位置</param>
        /// <param name="tabPage">要添加的TabPage</param>
        internal void Insert(int index, TabPagePlus tabPage)
        {
            if (index < 0 || index > this.tabPages.Length)
            {
                throw new ArgumentOutOfRangeException("索引:" + index + " 超出TabPages范围");
            }

            TabPagePlus[] tabPages_tmp = new TabPagePlus[this.tabPages.Length + 1];
            int k = 0;
            for (int i = 0; i <= this.tabPages.Length; i++)
            {
                if (i == index)
                {
                    tabPages_tmp[i] = tabPage;
                }
                else
                {
                    tabPages_tmp[i] = this.tabPages[k];
                    k++;
                }
            }
            if (this.tabbar_items_start_index < 0)
            {
                this.tabbar_items_start_index = 0;
            }

            this.tabPages = tabPages_tmp;
            this.InitializeElement();
            this.Invalidate();

            if (this.tsdd != null && this.tsdd.Visible)
            {
                this.tsdd.Close();
            }

            if ((this.SelectedIndex < 0 || this.SelectedIndex >= this.tabPages.Length) && this.tabPages.Length > 0)
            {
                this.SelectedIndex = 0;
            }

        }

        /// <summary>
        /// 移除所有TabPage
        /// </summary>
        internal void RemoveAll()
        {
            this.Controls.Clear();
            this.tabPages = new TabPagePlus[0];

            this.tabbar_items_start_index = 0;
            if (this.SelectedIndex == -1)
            {
                this.ReplenishSelectTabItemToRectangle();
                this.Invalidate();
            }
            else
            {
                this.SelectedIndex = -1;
            }

            if (this.tsdd != null && this.tsdd.Visible)
            {
                this.tsdd.Close();
            }
        }

        /// <summary>
        /// 移除指定索引的TabPage
        /// </summary>
        /// <param name="index">指定索引</param>
        internal void RemoveTabPage(int index)
        {
            if (index < 0 || index >= this.TabCount)
            {
                throw new ArgumentOutOfRangeException("索引:" + index + " 超出TabPages范围");
            }

            TabPagePlus old_tabPage = this.SelectedTab;
            int old_tabPageIndex = this.SelectedIndex;
            int k = 0;
            TabPagePlus[] tabPages_tmp = new TabPagePlus[this.TabCount - 1];
            for (int i = 0; i < this.tabPages.Length; i++)
            {
                if (i != index)
                {
                    tabPages_tmp[k] = this.tabPages[i];
                    k++;
                }
                else
                {
                    this.tabPages[i].Visible = false;
                }
            }
            this.tabPages = tabPages_tmp;

            if (this.tsdd != null && this.tsdd.Visible)
            {
                this.tsdd.Close();
            }

            if (this.SelectedIndex == -1 || index > old_tabPageIndex)
            {
                //更新画面信息
                this.InitializeElement();
                this.Invalidate();
                return;
            }

            if (this.TabCount < 1 && this.SelectedIndex != -1)
            {
                this.selectedIndex = -1;
                //选中索引更改事件
                this.OnSelectedIndexChanged(new TabControlPlusTabItemOperatedEventArgs(this.SelectedTab));

                //更新画面信息
                this.InitializeElement();
                this.Invalidate();
                return;
            }
            if (index < old_tabPageIndex)
            {
                this.selectedIndex -= 1;
                //选中索引更改事件
                this.OnSelectedIndexChanged(new TabControlPlusTabItemOperatedEventArgs(this.SelectedTab));

                //更新画面信息
                this.InitializeElement();
                this.Invalidate();
                return;
            }


            int left_start_index = index;
            if (this.selectedIndex == this.TabCount || index == old_tabPageIndex)
            {
                left_start_index -= 1;
            }
            //往左边找激活页
            for (int i = left_start_index; i >= 0; i--)
            {
                TabPagePlus new_tabPage = this.GetTabPage(i);

                // 新选项选中中事件
                TabControlPlusTabItemOperatingEventArgs selecting_arg = new TabControlPlusTabItemOperatingEventArgs(new_tabPage, false);
                this.OnTabItemSelecting(selecting_arg);
                if (selecting_arg.Cancel)
                {
                    continue;
                }
                else
                {
                    // 新选项选中后事件
                    TabControlPlusTabItemOperatedEventArgs selected_arg = new TabControlPlusTabItemOperatedEventArgs(new_tabPage);
                    this.OnTabItemSelected(selected_arg);

                    this.selectedIndex = i;
                    //选中索引更改事件
                    this.OnSelectedIndexChanged(new TabControlPlusTabItemOperatedEventArgs(this.SelectedTab));

                    //更新画面信息
                    this.InitializeElement();
                    this.Invalidate();

                    this.SetActiveTabPage(this.selectedIndex);
                    return;
                }
            }
            int right_start_index = index;
            //往右边找激活页
            for (int i = right_start_index; i < this.TabCount; i++)
            {
                TabPagePlus new_tabPage = this.GetTabPage(i);

                // 新选项选中中事件
                TabControlPlusTabItemOperatingEventArgs selecting_arg = new TabControlPlusTabItemOperatingEventArgs(new_tabPage, false);
                this.OnTabItemSelecting(selecting_arg);
                if (selecting_arg.Cancel)
                {
                    continue;
                }
                else
                {
                    // 新选项选中后事件
                    TabControlPlusTabItemOperatedEventArgs selected_arg = new TabControlPlusTabItemOperatedEventArgs(new_tabPage);
                    this.OnTabItemSelected(selected_arg);

                    this.selectedIndex = i;
                    //选中索引更改事件
                    this.OnSelectedIndexChanged(new TabControlPlusTabItemOperatedEventArgs(this.SelectedTab));

                    //更新画面信息
                    this.InitializeElement();
                    this.Invalidate();

                    this.SetActiveTabPage(this.selectedIndex);
                    return;
                }
            }

            //没有找到可以激活的页        
            this.selectedIndex = -1;
            this.InitializeElement();
            this.Invalidate();

            this.SetActiveTabPage(this.selectedIndex);

        }

        /// <summary>
        /// 设置指定索引的TabPage
        /// </summary>
        /// <param name="index">指定索引</param>
        /// <param name="tabPage">要设置的TabPage页</param>
        internal void SetTabPage(int index, TabPagePlus tabPage)
        {
            if (index < 0 || index >= this.TabCount)
            {
                throw new ArgumentOutOfRangeException("索引:" + index + " 超出TabPages范围");
            }
            tabPage.Visible = this.tabPages[index].Visible;
            this.tabPages[index] = tabPage;

            if (this.tsdd != null && this.tsdd.Visible)
            {
                this.tsdd.Close();
            }
        }

        /// <summary>
        /// 设置指定索引TabPage为选中
        /// </summary>
        /// <param name="index">指定索引</param>
        public void SelectTab(int index)
        {
            this.SelectedIndex = index;
        }

        /// <summary>
        /// 设置指定TabPage为选中
        /// </summary>
        /// <param name="tabPage">指定TabPage</param>
        public void SelectTab(TabPagePlus tabPage)
        {
            int index = this.FindTabPage(tabPage);
            this.SelectTab(index);
        }

        /// <summary>
        /// 设置指定Name属性值的TabPage为选中
        /// </summary>
        /// <param name="tabPageName">指定Name属性值</param>
        public void SelectTab(string tabPageName)
        {
            if (tabPageName == null)
            {
                throw new ArgumentNullException("tabPageName不允许为null");
            }

            TabPagePlus tabPage = this.TabPages[tabPageName];
            this.SelectTab(tabPage);
        }

        /// <summary>
        /// 取消指定索引TabPage的选中状态
        /// </summary>
        /// <param name="index">指定索引</param>
        public void DeselectTab(int index)
        {
            if (this.SelectedIndex == index)
            {
                if (this.TabCount > 1)
                {
                    if (index > 0)
                    {
                        this.SelectedIndex -= 1;
                    }
                    else
                    {
                        int index_tmp = index += 1;
                        if (index_tmp >= this.TabCount)
                        {
                            this.SelectedIndex = -1;
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 取消指定TabPage的选中状态
        /// </summary>
        /// <param name="tabPage">指定TabPage</param>
        public void DeselectTab(TabPagePlus tabPage)
        {
            if (tabPage == null)
            {
                throw new ArgumentNullException("tabPage不允许为null");
            }

            int index = this.FindTabPage(tabPage);
            this.DeselectTab(index);
        }

        /// <summary>
        /// 取消指定Name属性值的TabPage的选中状态
        /// </summary>
        /// <param name="tabPageName">指定Name属性值</param>
        public void DeselectTab(string tabPageName)
        {
            if (tabPageName == null)
            {
                throw new ArgumentNullException("tabPageName不允许为null");
            }
            TabPagePlus tabPage = this.TabPages[tabPageName];
            this.DeselectTab(tabPage);
        }

        /// <summary>
        /// 查找指定TabPage的索引
        /// </summary>
        /// <param name="tabPage">指定TabPage</param>
        /// <returns>找不到返回-1</returns>
        public int FindTabPage(TabPagePlus tabPage)
        {
            if (this.tabPages != null)
            {
                for (int i = 0; i < this.TabCount; i++)
                {
                    if (this.tabPages[i].Equals(tabPage))
                    {
                        return i;
                    }
                }
            }
            return -1;
        }

        /// <summary>
        /// 调换两个TabItem的位置
        /// </summary>
        /// <param name="currentTabPage">当前要移动的TabPage</param>
        /// <param name="targetTabPage">当前要移动的目标TabPage</param>
        internal void InterchangeTabItemIndex(TabPagePlus currentTabPage, TabPagePlus targetTabPage)
        {
            if (this.TabCount <= 0 || currentTabPage == targetTabPage)
                return;

            int current_index = this.FindTabPage(currentTabPage);
            int target_index = this.FindTabPage(targetTabPage);
            if (current_index > -1 && target_index > -1)
            {
                TabPagePlus[] tabPages_tmp = new TabPagePlus[this.TabCount];
                Array.Copy(tabPages, 0, tabPages_tmp, 0, this.TabCount);

                TabPagePlus tmp = tabPages_tmp[target_index];
                tabPages_tmp[target_index] = currentTabPage;
                tabPages_tmp[current_index] = tmp;
                this.tabPages = tabPages_tmp;

                if (this.selectedIndex == current_index)
                {
                    this.selectedIndex = target_index;
                }
                else if (this.selectedIndex != current_index && this.selectedIndex == target_index)
                {
                    this.selectedIndex = current_index;
                }

                this.UpdateEveryOneTabItemRectangle();
                this.ReplenishSelectTabItemToRectangle();
                this.Invalidate();

                if (this.tsdd != null && this.tsdd.Visible)
                {
                    this.tsdd.Close();
                }

            }

        }

        /// <summary>
        /// 获取主体区域Rect(排除外边框)
        /// </summary>
        public Rectangle GetBodyDisplayRectangle()
        {
            return this.body_c_rect;
        }

        /// <summary>
        /// 根据指定索引返回TabPage
        /// </summary>
        /// <param name="index">指定索引</param>
        /// <returns></returns>
        public Control GetControl(int index)
        {
            return (Control)this.GetTabPage(index);
        }

        /// <summary>
        /// 根据指定索引返回TabPage
        /// </summary>
        /// <param name="index">指定索引</param>
        /// <returns></returns>
        internal TabPagePlus GetTabPage(int index)
        {
            if (index < 0 || index >= this.TabCount)
            {
                return null;
            }
            return this.tabPages[index];
        }

        /// <summary>
        /// 获取TabPage数组
        /// </summary>
        /// <returns></returns>
        internal TabPagePlus[] GetTabPages()
        {
            return (TabPagePlus[])this.GetItems();
        }

        /// <summary>
        /// 获取TabPage数组
        /// </summary>
        /// <returns></returns>
        protected virtual object[] GetItems()
        {
            TabPagePlus[] result = new TabPagePlus[this.TabCount];
            if (this.TabCount > 0)
            {
                Array.Copy(tabPages, 0, result, 0, this.TabCount);
            }
            return result;
        }

        /// <summary>
        ///鼠标是否进入指定选项
        /// </summary>
        /// <param name="tabPage">指定TabPage</param>
        /// <returns></returns>
        internal bool IsMouseEnter(TabPagePlus tabPage)
        {
            return (tabPage != null && this.FindTabPage(tabPage) > -1 && this.mouseenterobject == tabPage);
        }

        /// <summary>
        /// 鼠标是否进入对象
        /// </summary>
        /// <param name="obj">对象</param>
        /// <returns></returns>
        internal bool IsMouseEnter(object obj)
        {
            return (obj != null && this.mouseenterobject == obj);
        }

        /// <summary>
        /// 判断坐标是否在导航栏按钮中(设计器使用)
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        [EditorBrowsable(EditorBrowsableState.Never)]
        internal bool JudgePointNavigationButton(Point point)
        {
            if (this.TabBar.NavigationBar.Visible == false || this.tabbar_navigationbar_visualstatus == false)
            {
                return false;
            }

            if (this.tabbar_navigationbar_c_rect.Contains(point))
            {
                if (this.TabBar.NavigationBar.PrevButton.C_Rect.Contains(point))
                {
                    return true;
                }
                if (this.TabBar.NavigationBar.NextButton.C_Rect.Contains(point))
                {
                    return true;
                }
            }

            return false;
        }

        /// <summary>
        /// 判断坐标是否在选卡项中(设计器使用)
        /// </summary>
        /// <param name="point">坐标</param>
        /// <returns></returns>
        [EditorBrowsable(EditorBrowsableState.Never)]
        internal bool JudgePointInItem(Point point)
        {
            bool result = false;
            if (this.tabbar_items_c_rect.Contains(point))
            {
                for (int i = 0; i < this.TabPages.Count; i++)
                {
                    if (this.TabPages[i].P_GP.IsVisible(point))
                    {
                        result = true;
                        break;
                    }
                }
            }
            return result;
        }




        /// <summary>
        /// 获取指定选项是否为自动宽度
        /// </summary>
        /// <param name="tabPage">指定TabPage</param>
        /// <returns></returns>
        public bool GetProperty_ItemAutoWidth(TabPagePlus tabPage)
        {
            if (tabPage.TabItem.AutoWidth == TabControlPlusTabItemAutoWidthMode.Auto)
            {
                return this.TabBar.TabItem.AutoWidth;
            }
            else
            {
                return tabPage.TabItem.AutoWidth == TabControlPlusTabItemAutoWidthMode.True ? true : false;
            }
        }

        /// <summary>
        /// 获取指定选项自动宽度最小宽度
        /// </summary>
        /// <param name="tabPage">指定TabPage</param>
        /// <returns></returns>
        public int GetProperty_ItemAutoWidthMin(TabPagePlus tabPage)
        {
            return tabPage.TabItem.AutoWidthMin == -1 ? this.TabBar.TabItem.AutoWidthMin : tabPage.TabItem.AutoWidthMin;
        }

        /// <summary>
        /// 获取指定TabPage左边外边距
        /// </summary>
        /// <param name="tabPage">指定TabPage</param>
        /// <returns></returns>
        public int GetProperty_ItemLeftMargin(TabPagePlus tabPage)
        {
            return tabPage.TabItem.LRMargin.Left == -1 ? this.TabBar.TabItem.LRMargin.Left : tabPage.TabItem.LRMargin.Left;
        }

        /// <summary>
        /// 获取指定TabPage右边外边距
        /// </summary>
        /// <param name="tabPage">指定TabPage</param>
        /// <returns></returns>
        public int GetProperty_ItemRightMargin(TabPagePlus tabPage)
        {
            return tabPage.TabItem.LRMargin.Right == -1 ? this.TabBar.TabItem.LRMargin.Right : tabPage.TabItem.LRMargin.Right;
        }

        /// <summary>
        /// 获取指定TabPage左边内边距
        /// </summary>
        /// <param name="tabPage">指定选项</param>
        /// <returns></returns>
        public int GetProperty_ItemLeftPadding(TabPagePlus tabPage)
        {
            return tabPage.TabItem.LRPadding.Left == -1 ? this.TabBar.TabItem.LRPadding.Left : tabPage.TabItem.LRPadding.Left;
        }

        /// <summary>
        /// 获取指定TabPage右边内边距 
        /// </summary>
        /// <param name="tabPage">指定TabPage</param>
        /// <returns></returns>
        public int GetProperty_ItemRightPadding(TabPagePlus tabPage)
        {
            return tabPage.TabItem.LRPadding.Right == -1 ? this.TabBar.TabItem.LRPadding.Right : tabPage.TabItem.LRPadding.Right;
        }

        /// <summary>
        /// 获取指定TabPage的背景颜色
        /// </summary>
        /// <param name="tabPage">指定TabPage</param>
        /// <returns></returns>
        public Color GetProperty_ItemBackColor(TabPagePlus tabPage)
        {
            bool isdisable = (!this.Enabled || !tabPage.TabItem.Enabled);
            if (!this.Enabled || !tabPage.TabItem.Enabled)
            {
                return this.StyleAppearance.TabBar.TabItem.Disabled.BackColor;
            }
            else if (this.JudgeTabPageIsSelect(tabPage))
            {
                return this.StyleAppearance.TabBar.TabItem.Selected.BackColor;
            }
            else if (tabPage.IsMouseEnter)
            {
                return this.StyleAppearance.TabBar.TabItem.Enter.BackColor;
            }
            else
            {
                return this.StyleAppearance.TabBar.TabItem.Normal.BackColor;
            }
        }

        /// <summary>
        /// 获取指定TabPage的文本颜色
        /// </summary>
        /// <param name="tabPage">指定TabPage</param>
        /// <returns></returns>
        public Color GetProperty_ItemTextColor(TabPagePlus tabPage)
        {
            if (!this.Enabled || !tabPage.TabItem.Enabled)
            {
                return this.StyleAppearance.TabBar.TabItem.Disabled.TextColor;
            }
            else if (this.JudgeTabPageIsSelect(tabPage))
            {
                return this.StyleAppearance.TabBar.TabItem.Selected.TextColor;
            }
            else if (tabPage.IsMouseEnter)
            {
                return this.StyleAppearance.TabBar.TabItem.Enter.TextColor;
            }
            else
            {
                return this.StyleAppearance.TabBar.TabItem.Normal.TextColor;
            }
        }

        /// <summary>
        /// 获取指定TabPage是否显示图标
        /// </summary>
        /// <param name="tabPage">指定TabPage</param>
        /// <returns></returns>
        public bool GetProperty_ItemIcoVisible(TabPagePlus tabPage)
        {
            if (tabPage.TabItem.Icon.Visible == TabControlPlusTabItemIconVisibles.Auto)
            {
                return this.TabBar.TabItem.Icon.Visible;
            }
            else
            {
                return tabPage.TabItem.Icon.Visible == TabControlPlusTabItemIconVisibles.True ? true : false;
            }
        }

        /// <summary>
        /// 获取指定TabPage图标
        /// </summary>
        /// <param name="tabPage">指定TabPage</param>
        /// <param name="ico_image">返回ico图片</param>
        /// <param name="ico_image_istmp">返回ico图片是否为临时（如果是,用完需要手动释放）</param>
        public void GetProperty_ItemIcoImage(TabPagePlus tabPage, ref Image ico_image, ref bool ico_image_istmp)
        {
            ico_image_istmp = false;
            ico_image = tabPage.TabItem.Icon.Image != null ? tabPage.TabItem.Icon.Image : HML.TabControlPlusResources.TabControlPlus_item_default_ico;
            if (!this.Enabled || !tabPage.TabItem.Enabled)
            {
                ico_image_istmp = true;
                ico_image = ControlHelper.CreateDisabledImage(ico_image);
            }
        }

        /// <summary>
        /// 获取指定TabPage是否显示关闭按钮
        /// </summary>
        /// <param name="tabPage">指定TabPage</param>
        /// <returns></returns>
        public bool GetProperty_ItemColseVisible(TabPagePlus tabPage)
        {
            if (tabPage.TabItem.CloseButton.Visible == TabControlPlusTabItemCloseButtonVisibles.Auto)
            {
                return this.TabBar.TabItem.CloseButton.Visible;
            }
            else
            {
                return tabPage.TabItem.CloseButton.Visible == TabControlPlusTabItemCloseButtonVisibles.True ? true : false;
            }
        }

        /// <summary>
        /// 获取指定TabPage自定义按钮的图片
        /// </summary>
        /// <param name="tabPage">指定TabPage</param>
        /// <param name="btn">自定义按钮</param>
        /// <param name="btn_image">返回按钮图片</param>
        /// <param name="btn_image_istmp">返回按钮图片是否为临时（如果是,用完需要手动释放）</param>
        public void GetProperty_ItemCustomButttonImage(TabPagePlus tabPage, TabControlPlusTabItemCustomButton btn, ref Image btn_image, ref bool btn_image_istmp)
        {
            btn_image_istmp = false;
            if (btn.CheckButton && btn.Checked)
            {
                btn_image = this.mouseenterobjectchildren == btn ? btn.CheckedStyleAppearance.Enter.Image : btn.CheckedStyleAppearance.Normal.Image;
                if (btn_image == null)
                {
                    btn_image = HML.TabControlPlusResources.TabControlPlus_item_default_button_ico;
                }

                if (!tabPage.TabItem.Enabled || !btn.Enabled)
                {
                    btn_image_istmp = true;
                    btn_image = ControlHelper.CreateDisabledImage(btn_image);
                }
            }
            else
            {
                btn_image = this.mouseenterobjectchildren == btn ? btn.UnCheckedStyleAppearance.Enter.Image : btn.UnCheckedStyleAppearance.Normal.Image;
                if (btn_image == null)
                {
                    btn_image = HML.TabControlPlusResources.TabControlPlus_item_default_button_ico;
                }

                if (!tabPage.TabItem.Enabled || !btn.Enabled)
                {
                    btn_image_istmp = true;
                    btn_image = ControlHelper.CreateDisabledImage(btn_image);
                }
            }
        }

        /// <summary>
        /// 显示下拉面板
        /// </summary>
        /// <param name="target_rect">相对于TabControlPlus控件RectangleF</param>
        public void ShowPicker(RectangleF target_rect)
        {
            if (this.pickerObject == null)
            {
                this.pickerObject = new TabControlPlusPicker(this);
            }
            if (this.tsdd == null)
            {
                this.tsdd = new ToolStripDropDown() { Padding = Padding.Empty };
            }
            if (this.tsch == null)
            {
                this.tsch = new ToolStripControlHost(this.pickerObject) { Margin = Padding.Empty, Padding = Padding.Empty };
                tsdd.Items.Add(this.tsch);
            }

            int picker_space = 4;
            target_rect = new RectangleF(this.PointToScreen(new Point((int)target_rect.Location.X, (int)target_rect.Location.Y)), target_rect.Size);
            Rectangle screen_rect = Screen.GetWorkingArea(this);
            int scale_item_height = (int)Math.Ceiling(this.Picker.TabItem.Height * this.ScaleDpi);
            int scale_item_width = (int)(200 * this.ScaleDpi);
            for (int i = 0; i < this.TabPages.Count; i++)
            {
                if (this.TabPages[i].Picker_Text_Size.Width > scale_item_width)
                {
                    scale_item_width = this.TabPages[i].Picker_Text_Size.Width;
                }
            }

            Size scale_picker_maxsize = Size.Ceiling(new SizeF(this.Picker.MaxSize.Width * this.ScaleDpi, this.Picker.MaxSize.Height * this.ScaleDpi));
            int scale_picker_width = Math.Min(scale_item_width, scale_picker_maxsize.Width);
            int scale_picker_height = Math.Min(scale_item_height * this.TabPages.Count, scale_picker_maxsize.Height);

            Point point = Point.Empty;
            if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Top)
            {
                point = new Point((int)(target_rect.X + target_rect.Width * 2 - scale_picker_width), (int)(target_rect.Bottom + picker_space));//下拉框Top默认位置
                if (point.Y + scale_picker_height > screen_rect.Bottom - picker_space)//下拉框高度超过屏幕底部
                {
                    if (target_rect.Y > screen_rect.Height * 3 / 4)//下拉框Top默认位置在屏幕高度3/4下面
                    {
                        if (target_rect.Y - picker_space - scale_picker_height < 0)
                        {
                            scale_picker_height = (int)target_rect.Y - picker_space * 2;//下拉框高度不能超过屏幕顶部
                        }
                        point = new Point((int)(target_rect.X + target_rect.Width * 2 - scale_picker_width), (int)(target_rect.Y - picker_space - scale_picker_height));//下拉框改为Bottom默认位置
                    }
                    else
                    {
                        scale_picker_height = screen_rect.Bottom - point.Y - picker_space;//下拉框高度不能超过屏幕底部
                    }
                }
            }
            else if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Bottom || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Right)
            {
                point = new Point((int)(Math.Min(target_rect.X + target_rect.Width * 2 - scale_picker_width, screen_rect.Right - picker_space - scale_picker_width)), (int)(target_rect.Y - picker_space - scale_picker_height));//下拉框Bottom默认位置
                if (point.Y < screen_rect.Y + picker_space)//下拉框高度超过屏幕顶部
                {
                    if (target_rect.Y < screen_rect.Height / 4)//下拉框Bottom默认位置在屏幕高度1/4上面
                    {
                        point = new Point((int)(Math.Min(target_rect.X + target_rect.Width * 2 - scale_picker_width, screen_rect.Right - picker_space - scale_picker_width)), (int)(target_rect.Bottom + picker_space));//下拉框改为Top默认位置
                        if (point.Y + scale_picker_height > screen_rect.Bottom - picker_space)
                        {
                            scale_picker_height = (int)screen_rect.Bottom - point.Y - picker_space;//下拉框高度不能超过屏幕底部
                        }
                    }
                    else
                    {
                        point = new Point((int)(Math.Min(target_rect.X + target_rect.Width * 2 - scale_picker_width, screen_rect.Right - picker_space - scale_picker_width)), (int)(screen_rect.Y + picker_space));//下拉框Bottom默认位置
                        scale_picker_height = (int)target_rect.Y - picker_space * 2;//下拉框高度不能超过屏幕顶部
                    }
                }
            }
            else if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Left)
            {
                if (this.TabBar.TabItem.VerticalLayout)
                {
                    point = new Point((int)(Math.Max(target_rect.X - target_rect.Width, screen_rect.X + picker_space)), (int)(target_rect.Y - picker_space - scale_picker_height));//下拉框Bottom默认位置
                    if (point.Y < screen_rect.Y + picker_space)//下拉框高度超过屏幕顶部
                    {
                        if (target_rect.Y < screen_rect.Height / 4)//下拉框Bottom默认位置在屏幕高度1/4上面
                        {
                            point = new Point((int)(Math.Max(target_rect.X - target_rect.Width, screen_rect.X + picker_space)), (int)(target_rect.Bottom + picker_space));//下拉框改为Top默认位置
                            if (point.Y + scale_picker_height > screen_rect.Bottom - picker_space)
                            {
                                scale_picker_height = (int)screen_rect.Bottom - point.Y - picker_space;//下拉框高度不能超过屏幕底部
                            }
                        }
                        else
                        {
                            point = new Point((int)(Math.Max(target_rect.X - target_rect.Width, screen_rect.X + picker_space)), (int)(screen_rect.Y + picker_space));//下拉框Bottom默认位置
                            scale_picker_height = (int)target_rect.Y - picker_space * 2;//下拉框高度不能超过屏幕顶部
                        }
                    }
                }
                else
                {
                    point = new Point((int)(Math.Max(target_rect.X + target_rect.Width * 2 - scale_picker_width, screen_rect.X + picker_space)), (int)(target_rect.Y - picker_space - scale_picker_height));//下拉框Bottom默认位置
                    if (point.Y < screen_rect.Y + picker_space)//下拉框高度超过屏幕顶部
                    {
                        if (target_rect.Y < screen_rect.Height / 4)//下拉框Bottom默认位置在屏幕高度1/4上面
                        {
                            point = new Point((int)(Math.Max(target_rect.X + target_rect.Width * 2 - scale_picker_width, screen_rect.X + picker_space)), (int)(target_rect.Bottom + picker_space));//下拉框改为Top默认位置
                            if (point.Y + scale_picker_height > screen_rect.Bottom - picker_space)
                            {
                                scale_picker_height = (int)screen_rect.Bottom - point.Y - picker_space;//下拉框高度不能超过屏幕底部
                            }
                        }
                        else
                        {
                            point = new Point((int)(Math.Max(target_rect.X + target_rect.Width * 2 - scale_picker_width, screen_rect.X + picker_space)), (int)(screen_rect.Y + picker_space));//下拉框Bottom默认位置
                            scale_picker_height = (int)target_rect.Y - picker_space * 2;//下拉框高度不能超过屏幕顶部
                        }
                    }
                }

            }

            this.pickerObject.Size = new Size(scale_picker_width, scale_picker_height);

            this.pickerObject.InitializeElement();
            this.pickerObject.InitializeStatus();
            tsdd.Show(point);
        }

        /// <summary>
        /// 隐藏下拉面板
        /// </summary>
        public void HidePicker()
        {
            if (this.tsdd == null)
                return;

            this.tsdd.Close();
        }

        #endregion

        #region 私有方法

        /// <summary>
        /// 更新每一个tabitem选项size
        /// </summary>
        private void UpdateEveryOneTabItemSize()
        {
            IntPtr hDC = IntPtr.Zero;
            Graphics g = null;
            ControlHelper.GetWindowClientGraphics(this.Handle, out g, out hDC);

            NativeMethods.TEXTMETRIC font_metrics = ControlHelper.GetFontMetrics(this.Handle, this.Font);

            //选项
            bool tabbar_item_auto_width = false;
            int scale_tabbar_item_auto_width_min = 0;
            Size scale_tabbar_item_size = Size.Ceiling(new SizeF(this.TabBar.TabItem.Size.Width * this.ScaleDpi, this.TabBar.TabItem.Size.Height * this.ScaleDpi));
            int scale_tabbar_item_left_padding = 0;
            int scale_tabbar_item_right_padding = 0;
            int scale_tabbar_item_p_width = 0;
            //选项图标
            bool scale_tabbar_item_ico_visible = false;
            Size scale_tabbar_item_ico_size = Size.Ceiling(new SizeF(this.TabBar.TabItem.Icon.Size.Width * this.ScaleDpi, this.TabBar.TabItem.Icon.Size.Height * this.ScaleDpi));
            int scale_tabbar_item_ico_left_margin = 0;
            int scale_tabbar_item_ico_right_margin = 0;
            int scale_tabbar_item_ico_m_width = 0;
            //选关闭按钮
            bool tabbar_item_closebutton_visible = false;
            Size scale_tabbar_item_closebutton_size = Size.Ceiling(new SizeF(this.TabBar.TabItem.CloseButton.Size.Width * this.ScaleDpi, this.TabBar.TabItem.CloseButton.Size.Height * this.ScaleDpi));
            int scale_tabbar_item_closebutton_left_margin = 0;
            int scale_tabbar_item_closebutton_right_margin = 0;
            int scale_tabbar_item_closebutton_m_width = 0;
            //选项自定义按钮
            int scale_tabbar_item_custombuttons_width_sum = 0;//自定义按钮总宽度 

            //计算选项rect
            for (int i = 0; i < this.TabCount; i++)
            {
                TabPagePlus tabPage = this.TabPages[i];

                tabbar_item_auto_width = this.GetProperty_ItemAutoWidth(tabPage);
                scale_tabbar_item_auto_width_min = (int)Math.Ceiling(this.GetProperty_ItemAutoWidthMin(tabPage) * this.ScaleDpi);
                scale_tabbar_item_left_padding = (int)Math.Ceiling(this.GetProperty_ItemLeftPadding(tabPage) * this.ScaleDpi);
                scale_tabbar_item_right_padding = (int)Math.Ceiling(this.GetProperty_ItemRightPadding(tabPage) * this.ScaleDpi);

                scale_tabbar_item_ico_visible = this.GetProperty_ItemIcoVisible(tabPage);
                scale_tabbar_item_ico_left_margin = (int)Math.Ceiling(this.TabBar.TabItem.Icon.LRMargin.Left * this.ScaleDpi);
                scale_tabbar_item_ico_right_margin = (int)Math.Ceiling(this.TabBar.TabItem.Icon.LRMargin.Right * this.ScaleDpi);

                tabbar_item_closebutton_visible = this.GetProperty_ItemColseVisible(tabPage);
                scale_tabbar_item_closebutton_left_margin = (int)Math.Ceiling(this.TabBar.TabItem.CloseButton.LRMargin.Left * this.ScaleDpi);
                scale_tabbar_item_closebutton_right_margin = (int)Math.Ceiling(this.TabBar.TabItem.CloseButton.LRMargin.Right * this.ScaleDpi);

                scale_tabbar_item_custombuttons_width_sum = 0;//自定义按钮总宽度
                foreach (TabControlPlusTabItemCustomButton btn in tabPage.TabItem.CustomButtons)
                {
                    if (btn.Visible)
                    {
                        Size scale_btn_size = Size.Ceiling(new SizeF(btn.Size.Width * this.ScaleDpi, btn.Size.Height * this.ScaleDpi));
                        int scale_btn_margin_left = (int)Math.Ceiling(btn.LRMargin.Left * this.ScaleDpi);
                        int scale_btn_margin_right = (int)Math.Ceiling(btn.LRMargin.Right * this.ScaleDpi);
                        scale_tabbar_item_custombuttons_width_sum += scale_btn_margin_left + scale_btn_size.Width + scale_btn_margin_right;
                    }
                }

                scale_tabbar_item_ico_m_width = 0;
                if (scale_tabbar_item_ico_visible)
                {
                    scale_tabbar_item_ico_m_width = scale_tabbar_item_ico_left_margin + scale_tabbar_item_ico_size.Width + scale_tabbar_item_ico_right_margin;
                }

                scale_tabbar_item_closebutton_m_width = 0;
                if (tabbar_item_closebutton_visible)
                {
                    scale_tabbar_item_closebutton_m_width = scale_tabbar_item_closebutton_left_margin + scale_tabbar_item_closebutton_size.Width + scale_tabbar_item_closebutton_right_margin;
                }

                tabPage.Picker_Text_Size = new Size((int)Math.Ceiling(g.MeasureString(tabPage.Text, this.Picker.Font, int.MaxValue).Width), font_metrics.GetFontRealHeight());

                if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Top || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Bottom)
                {
                    if (tabbar_item_auto_width)//选项自动宽度模式
                    {
                        int tabbar_item_text_width = Size.Ceiling(g.MeasureString(tabPage.Text, this.Font, int.MaxValue)).Width;
                        scale_tabbar_item_p_width = Math.Max(scale_tabbar_item_auto_width_min, scale_tabbar_item_left_padding + scale_tabbar_item_ico_m_width + tabbar_item_text_width + scale_tabbar_item_custombuttons_width_sum + scale_tabbar_item_closebutton_m_width + scale_tabbar_item_right_padding);

                        tabPage.Text_C_Size = new Size(scale_tabbar_item_p_width - scale_tabbar_item_left_padding - scale_tabbar_item_ico_m_width - scale_tabbar_item_custombuttons_width_sum - scale_tabbar_item_closebutton_m_width - scale_tabbar_item_right_padding, font_metrics.GetFontRealHeight());
                        tabPage.Rect_C_Size = new Size(scale_tabbar_item_p_width - scale_tabbar_item_left_padding - scale_tabbar_item_right_padding, scale_tabbar_item_size.Height);
                    }
                    else//选项指定宽度模式
                    {
                        scale_tabbar_item_p_width = tabPage.TabItem.FixedWidth == -1 ? scale_tabbar_item_size.Width : (int)Math.Ceiling(tabPage.TabItem.FixedWidth * this.ScaleDpi);
                        int tabbar_item_text_width = Math.Max(0, (scale_tabbar_item_p_width - scale_tabbar_item_left_padding - scale_tabbar_item_ico_m_width - scale_tabbar_item_custombuttons_width_sum - scale_tabbar_item_closebutton_m_width - scale_tabbar_item_right_padding));

                        tabPage.Text_C_Size = new Size(tabbar_item_text_width, font_metrics.GetFontRealHeight());
                        tabPage.Rect_C_Size = new Size(scale_tabbar_item_p_width - scale_tabbar_item_left_padding - scale_tabbar_item_right_padding, scale_tabbar_item_size.Height);
                    }

                }
                else if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Left || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Right)
                {
                    if (this.TabBar.TabItem.VerticalLayout) //Tab选项是否纵向布局(限于左右两边)(依然存储横向的数据)
                    {
                        if (tabbar_item_auto_width)//自动宽度模式
                        {
                            int tabbar_item_text_width = 0;
                            if (tabPage.TabItem.VerticalLayout)
                            {
                                tabbar_item_text_width = tabPage.Text.Length * font_metrics.GetFontRealHeight();
                            }
                            else
                            {
                                tabbar_item_text_width = Size.Ceiling(g.MeasureString(tabPage.Text, this.Font, int.MaxValue)).Width;
                            }
                            scale_tabbar_item_p_width = Math.Max(scale_tabbar_item_auto_width_min, scale_tabbar_item_left_padding + scale_tabbar_item_ico_m_width + tabbar_item_text_width + scale_tabbar_item_custombuttons_width_sum + scale_tabbar_item_closebutton_m_width + scale_tabbar_item_right_padding);

                            tabPage.Text_C_Size = new Size(scale_tabbar_item_p_width - scale_tabbar_item_left_padding - scale_tabbar_item_ico_m_width - scale_tabbar_item_custombuttons_width_sum - scale_tabbar_item_closebutton_m_width - scale_tabbar_item_right_padding, font_metrics.GetFontRealHeight());
                            tabPage.Rect_C_Size = new Size(scale_tabbar_item_p_width - scale_tabbar_item_left_padding - scale_tabbar_item_right_padding, scale_tabbar_item_size.Height);

                        }
                        else//指定宽度模式
                        {
                            scale_tabbar_item_p_width = tabPage.TabItem.FixedWidth == -1 ? scale_tabbar_item_size.Width : (int)Math.Ceiling(tabPage.TabItem.FixedWidth * this.ScaleDpi);
                            int tabbar_item_text_width = Math.Max(0, (scale_tabbar_item_p_width - scale_tabbar_item_left_padding - scale_tabbar_item_ico_m_width - scale_tabbar_item_custombuttons_width_sum - scale_tabbar_item_closebutton_m_width - scale_tabbar_item_right_padding));

                            tabPage.Text_C_Size = new Size(tabbar_item_text_width, font_metrics.GetFontRealHeight());
                            tabPage.Rect_C_Size = new Size(scale_tabbar_item_p_width - scale_tabbar_item_left_padding - scale_tabbar_item_right_padding, scale_tabbar_item_size.Height);
                        }
                    }
                    else
                    {
                        scale_tabbar_item_p_width = scale_tabbar_item_size.Width;
                        int tabbar_item_text_width = Math.Max(0, (scale_tabbar_item_p_width - scale_tabbar_item_left_padding - scale_tabbar_item_ico_m_width - scale_tabbar_item_custombuttons_width_sum - scale_tabbar_item_closebutton_m_width - scale_tabbar_item_right_padding));
                        tabPage.Text_C_Size = new Size(tabbar_item_text_width, font_metrics.GetFontRealHeight());
                        tabPage.Rect_C_Size = new Size(scale_tabbar_item_p_width - scale_tabbar_item_left_padding - scale_tabbar_item_right_padding, scale_tabbar_item_size.Height);
                    }
                }

            }

            g.Dispose();
            NativeMethods.ReleaseDC(this.Handle, hDC);

        }

        /// <summary>
        /// 更新选项卡栏区域M_Rectangle(包含外边距)、C_Rectangle(排除外边距、边框、内边距)
        /// </summary>
        /// <returns></returns>
        private void UpdateTabBarRectangle()
        {
            Size scale_tabbar_item_size = Size.Ceiling(new SizeF(this.TabBar.TabItem.Size.Width * this.ScaleDpi, this.TabBar.TabItem.Size.Height * this.ScaleDpi));
            int scale_tabbar_padding_top = (int)Math.Ceiling(this.TabBar.Padding.Top * this.ScaleDpi);
            int scale_tabbar_padding_bottom = (int)Math.Ceiling(this.TabBar.Padding.Bottom * this.ScaleDpi);
            int scale_tabbar_padding_left = (int)Math.Ceiling(this.TabBar.Padding.Left * this.ScaleDpi);
            int scale_tabbar_padding_right = (int)Math.Ceiling(this.TabBar.Padding.Right * this.ScaleDpi);

            // 更新选项卡栏区域Rectangle信息
            if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Top)
            {
                this.tabbar_p_rect = new Rectangle(this.ClientRectangle.X, this.ClientRectangle.Y, this.ClientRectangle.Width, scale_tabbar_padding_top + scale_tabbar_item_size.Height + scale_tabbar_padding_bottom);
                this.tabbar_c_rect = new Rectangle(scale_tabbar_padding_left, scale_tabbar_padding_top, this.ClientRectangle.Width - scale_tabbar_padding_left - scale_tabbar_padding_right, scale_tabbar_item_size.Height);
            }
            else if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Bottom)
            {
                this.tabbar_p_rect = new Rectangle(this.ClientRectangle.X, this.ClientRectangle.Bottom - scale_tabbar_padding_bottom - scale_tabbar_item_size.Height - scale_tabbar_padding_top, this.ClientRectangle.Width, scale_tabbar_padding_top + scale_tabbar_item_size.Height + scale_tabbar_padding_bottom);
                this.tabbar_c_rect = new Rectangle(scale_tabbar_padding_left, this.ClientRectangle.Bottom - scale_tabbar_padding_top - scale_tabbar_item_size.Height, this.ClientRectangle.Width - scale_tabbar_padding_left - scale_tabbar_padding_right, scale_tabbar_item_size.Height);
            }
            else if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Left)
            {
                if (this.TabBar.TabItem.VerticalLayout)
                {
                    this.tabbar_p_rect = new Rectangle(this.ClientRectangle.X, this.ClientRectangle.Y, scale_tabbar_padding_top + scale_tabbar_item_size.Height + scale_tabbar_padding_bottom, this.ClientRectangle.Height);
                    this.tabbar_c_rect = new Rectangle(scale_tabbar_padding_top, scale_tabbar_padding_left, scale_tabbar_item_size.Height, this.ClientRectangle.Height - scale_tabbar_padding_left - scale_tabbar_padding_right);
                }
                else
                {
                    this.tabbar_p_rect = new Rectangle(this.ClientRectangle.X, this.ClientRectangle.Y, scale_tabbar_padding_top + scale_tabbar_item_size.Width + scale_tabbar_padding_bottom, this.ClientRectangle.Height);
                    this.tabbar_c_rect = new Rectangle(scale_tabbar_padding_top, scale_tabbar_padding_left, scale_tabbar_item_size.Width, this.ClientRectangle.Height - scale_tabbar_padding_left - scale_tabbar_padding_right);
                }
            }
            else if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Right)
            {
                if (this.TabBar.TabItem.VerticalLayout)
                {
                    this.tabbar_p_rect = new Rectangle(this.ClientRectangle.Right - scale_tabbar_padding_top - scale_tabbar_item_size.Height - scale_tabbar_padding_bottom, this.ClientRectangle.Y, scale_tabbar_padding_top + scale_tabbar_item_size.Height + scale_tabbar_padding_bottom, this.ClientRectangle.Height);
                    this.tabbar_c_rect = new Rectangle(this.ClientRectangle.Right - scale_tabbar_padding_top - scale_tabbar_item_size.Height, scale_tabbar_padding_left, scale_tabbar_item_size.Height, this.ClientRectangle.Height - scale_tabbar_padding_left - scale_tabbar_padding_right);
                }
                else
                {
                    this.tabbar_p_rect = new Rectangle(this.ClientRectangle.Right - scale_tabbar_padding_top - scale_tabbar_item_size.Width - scale_tabbar_padding_bottom, this.ClientRectangle.Y, scale_tabbar_padding_top + scale_tabbar_item_size.Width + scale_tabbar_padding_bottom, this.ClientRectangle.Height);
                    this.tabbar_c_rect = new Rectangle(this.ClientRectangle.Right - scale_tabbar_padding_top - scale_tabbar_item_size.Width, scale_tabbar_padding_left, scale_tabbar_item_size.Width, this.ClientRectangle.Height - scale_tabbar_padding_left - scale_tabbar_padding_right);
                }
            }

            //全局按钮
            if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Top || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Bottom)
            {
                int scale_tabbar_globalbuttton_width_sum = 0;
                for (int i = this.TabBar.GlobalButttons.Count - 1; i > -1; i--)
                {
                    TabControlPlusGlobalButtton btn = this.TabBar.GlobalButttons[i];
                    if (btn.Visible)
                    {
                        Size scale_btn_size = Size.Ceiling(new SizeF(btn.Size.Width * this.ScaleDpi, btn.Size.Height * this.ScaleDpi));
                        int scale_btn_margin_left = (int)Math.Ceiling(btn.LRMargin.Left * this.ScaleDpi);
                        int scale_btn_margin_right = (int)Math.Ceiling(btn.LRMargin.Right * this.ScaleDpi);

                        scale_tabbar_globalbuttton_width_sum += scale_btn_margin_left + scale_btn_size.Width + scale_btn_margin_right;
                    }
                }

                this.tabbar_globalbuttton_c_rect = new Rectangle(this.tabbar_c_rect.Right - scale_tabbar_globalbuttton_width_sum, this.tabbar_c_rect.Y, scale_tabbar_globalbuttton_width_sum, this.tabbar_c_rect.Height);

                float globalbuttton_x = this.tabbar_globalbuttton_c_rect.X;
                for (int i = this.TabBar.GlobalButttons.Count - 1; i > -1; i--)
                {
                    TabControlPlusGlobalButtton btn = this.TabBar.GlobalButttons[i];
                    if (btn.Visible)
                    {
                        Size scale_btn_size = Size.Ceiling(new SizeF(btn.Size.Width * this.ScaleDpi, btn.Size.Height * this.ScaleDpi));
                        int scale_btn_margin_left = (int)Math.Ceiling(btn.LRMargin.Left * this.ScaleDpi);
                        int scale_btn_margin_right = (int)Math.Ceiling(btn.LRMargin.Right * this.ScaleDpi);

                        btn.M_Rect = new RectangleF(globalbuttton_x, this.tabbar_globalbuttton_c_rect.Y + (this.tabbar_globalbuttton_c_rect.Height - scale_btn_size.Height) / 2f, scale_btn_margin_left + scale_btn_size.Width + scale_btn_margin_right, scale_btn_size.Height);
                        btn.C_Rect = new RectangleF(btn.M_Rect.X + scale_btn_margin_left, btn.M_Rect.Y, scale_btn_size.Width, scale_btn_size.Height);
                        globalbuttton_x = btn.M_Rect.Right;
                    }
                    else
                    {
                        btn.M_Rect = RectangleF.Empty;
                        btn.C_Rect = RectangleF.Empty;
                    }
                }
            }
            else if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Left || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Right)
            {
                if (this.TabBar.TabItem.VerticalLayout)
                {
                    int scale_tabbar_globalbuttton_width_sum = 0;
                    for (int i = this.TabBar.GlobalButttons.Count - 1; i > -1; i--)
                    {
                        TabControlPlusGlobalButtton btn = this.TabBar.GlobalButttons[i];
                        if (btn.Visible)
                        {
                            Size scale_btn_size = Size.Ceiling(new SizeF(btn.Size.Width * this.ScaleDpi, btn.Size.Height * this.ScaleDpi));
                            int scale_btn_margin_left = (int)Math.Ceiling(btn.LRMargin.Left * this.ScaleDpi);
                            int scale_btn_margin_right = (int)Math.Ceiling(btn.LRMargin.Right * this.ScaleDpi);
                            scale_tabbar_globalbuttton_width_sum += scale_btn_margin_left + scale_btn_size.Width + scale_btn_margin_right;
                        }
                    }

                    this.tabbar_globalbuttton_c_rect = new Rectangle(this.tabbar_c_rect.X, this.tabbar_c_rect.Bottom - scale_tabbar_globalbuttton_width_sum, scale_tabbar_item_size.Height, scale_tabbar_globalbuttton_width_sum);

                    float globalbuttton_y = this.tabbar_globalbuttton_c_rect.Y;
                    for (int i = this.TabBar.GlobalButttons.Count - 1; i > -1; i--)
                    {
                        TabControlPlusGlobalButtton btn = this.TabBar.GlobalButttons[i];
                        if (btn.Visible)
                        {
                            Size scale_btn_size = Size.Ceiling(new SizeF(btn.Size.Width * this.ScaleDpi, btn.Size.Height * this.ScaleDpi));
                            int scale_btn_margin_left = (int)Math.Ceiling(btn.LRMargin.Left * this.ScaleDpi);
                            int scale_btn_margin_right = (int)Math.Ceiling(btn.LRMargin.Right * this.ScaleDpi);

                            btn.M_Rect = new RectangleF(this.tabbar_globalbuttton_c_rect.X + (this.tabbar_globalbuttton_c_rect.Width - scale_btn_size.Height) / 2f, globalbuttton_y, scale_btn_size.Height, scale_btn_margin_left + scale_btn_size.Width + scale_btn_margin_right);
                            btn.C_Rect = new RectangleF(btn.M_Rect.X, btn.M_Rect.Y + scale_btn_margin_right, scale_btn_size.Height, scale_btn_size.Width);
                            globalbuttton_y = btn.M_Rect.Bottom;
                        }
                        else
                        {
                            btn.M_Rect = RectangleF.Empty;
                            btn.C_Rect = RectangleF.Empty;
                        }
                    }
                }
                else
                {
                    int scale_tabbar_globalbuttton_width_sum = 0;
                    for (int i = this.TabBar.GlobalButttons.Count - 1; i > -1; i--)
                    {
                        TabControlPlusGlobalButtton btn = this.TabBar.GlobalButttons[i];
                        if (btn.Visible)
                        {
                            Size scale_btn_size = Size.Ceiling(new SizeF(btn.Size.Width * this.ScaleDpi, btn.Size.Height * this.ScaleDpi));
                            int scale_btn_margin_left = (int)Math.Ceiling(btn.LRMargin.Left * this.ScaleDpi);
                            int scale_btn_margin_right = (int)Math.Ceiling(btn.LRMargin.Right * this.ScaleDpi);

                            scale_tabbar_globalbuttton_width_sum += scale_btn_margin_left + scale_btn_size.Width + scale_btn_margin_right;
                        }
                    }

                    this.tabbar_globalbuttton_c_rect = new Rectangle(this.tabbar_c_rect.Right - scale_tabbar_globalbuttton_width_sum, this.tabbar_c_rect.Bottom - scale_tabbar_item_size.Height, scale_tabbar_globalbuttton_width_sum, scale_tabbar_item_size.Height);

                    float globalbuttton_x = this.tabbar_globalbuttton_c_rect.X;
                    for (int i = this.TabBar.GlobalButttons.Count - 1; i > -1; i--)
                    {
                        TabControlPlusGlobalButtton btn = this.TabBar.GlobalButttons[i];
                        if (btn.Visible)
                        {
                            Size scale_btn_size = Size.Ceiling(new SizeF(btn.Size.Width * this.ScaleDpi, btn.Size.Height * this.ScaleDpi));
                            int scale_btn_margin_left = (int)Math.Ceiling(btn.LRMargin.Left * this.ScaleDpi);
                            int scale_btn_margin_right = (int)Math.Ceiling(btn.LRMargin.Right * this.ScaleDpi);

                            btn.M_Rect = new RectangleF(globalbuttton_x, this.tabbar_globalbuttton_c_rect.Y + (this.tabbar_globalbuttton_c_rect.Height - scale_btn_size.Height) / 2f, scale_btn_margin_left + scale_btn_size.Width + scale_btn_margin_right, scale_btn_size.Height);
                            btn.C_Rect = new RectangleF(btn.M_Rect.X + scale_btn_margin_left, btn.M_Rect.Y, scale_btn_size.Width, scale_btn_size.Height);
                            globalbuttton_x = btn.M_Rect.Right;
                        }
                        else
                        {
                            btn.M_Rect = RectangleF.Empty;
                            btn.C_Rect = RectangleF.Empty;
                        }
                    }
                }
            }


            // 导航栏Rectangle信息
            if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Top || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Bottom)
            {
                if (this.TabBar.NavigationBar.Visible)
                {
                    int scale_navigation_button_left = (int)Math.Ceiling(this.TabBar.NavigationBar.ButtonLRMargin.Left * this.ScaleDpi);
                    int scale_navigation_button_right = (int)Math.Ceiling(this.TabBar.NavigationBar.ButtonLRMargin.Right * this.ScaleDpi);
                    Size scale_navigation_prev_button_size = Size.Ceiling(new SizeF(this.TabBar.NavigationBar.ButtonSize.Width * this.ScaleDpi, this.TabBar.NavigationBar.ButtonSize.Height * this.ScaleDpi));
                    Size scale_navigation_next_button_size = Size.Ceiling(new SizeF(this.TabBar.NavigationBar.ButtonSize.Width * this.ScaleDpi, this.TabBar.NavigationBar.ButtonSize.Height * this.ScaleDpi));

                    int scale_tabbar_navigation_btn_width_sum = 0;
                    scale_tabbar_navigation_btn_width_sum += scale_navigation_button_left + scale_navigation_prev_button_size.Width + scale_navigation_button_right;
                    scale_tabbar_navigation_btn_width_sum += scale_navigation_button_left + scale_navigation_next_button_size.Width + scale_navigation_button_right;

                    this.tabbar_navigationbar_c_rect = new Rectangle(this.tabbar_c_rect.Right - this.tabbar_globalbuttton_c_rect.Width - scale_tabbar_navigation_btn_width_sum, this.tabbar_c_rect.Y, scale_tabbar_navigation_btn_width_sum, this.tabbar_c_rect.Height);

                    this.TabBar.NavigationBar.PrevButton.M_Rect = new Rectangle(this.tabbar_navigationbar_c_rect.X, this.tabbar_navigationbar_c_rect.Y + (this.tabbar_navigationbar_c_rect.Height - scale_navigation_prev_button_size.Height) / 2, scale_navigation_button_left + scale_navigation_prev_button_size.Width + scale_navigation_button_right, scale_navigation_prev_button_size.Height);
                    this.TabBar.NavigationBar.PrevButton.C_Rect = new Rectangle(this.TabBar.NavigationBar.PrevButton.M_Rect.X + scale_navigation_button_left, this.TabBar.NavigationBar.PrevButton.M_Rect.Y, scale_navigation_prev_button_size.Width, scale_navigation_prev_button_size.Height);

                    this.TabBar.NavigationBar.NextButton.M_Rect = new Rectangle(this.TabBar.NavigationBar.PrevButton.M_Rect.Right, this.tabbar_navigationbar_c_rect.Y + (this.tabbar_navigationbar_c_rect.Height - scale_navigation_next_button_size.Height) / 2, scale_navigation_button_left + scale_navigation_next_button_size.Width + scale_navigation_button_right, scale_navigation_next_button_size.Height);
                    this.TabBar.NavigationBar.NextButton.C_Rect = new Rectangle(this.TabBar.NavigationBar.NextButton.M_Rect.X + scale_navigation_button_left, this.TabBar.NavigationBar.NextButton.M_Rect.Y, scale_navigation_next_button_size.Width, scale_navigation_next_button_size.Height);
                }
                else
                {
                    this.tabbar_navigationbar_c_rect = new Rectangle(this.tabbar_c_rect.Right - this.tabbar_globalbuttton_c_rect.Width, this.tabbar_c_rect.Y, 0, this.tabbar_c_rect.Height);
                    this.TabBar.NavigationBar.PrevButton.M_Rect = Rectangle.Empty;
                    this.TabBar.NavigationBar.PrevButton.C_Rect = Rectangle.Empty;
                    this.TabBar.NavigationBar.NextButton.M_Rect = Rectangle.Empty;
                    this.TabBar.NavigationBar.NextButton.C_Rect = Rectangle.Empty;
                }
            }
            else if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Left || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Right)
            {
                if (this.TabBar.TabItem.VerticalLayout)//Tab选项是否垂直布局(限于左右两边)
                {
                    if (this.TabBar.NavigationBar.Visible)
                    {
                        int scale_navigation_button_left = (int)Math.Ceiling(this.TabBar.NavigationBar.ButtonLRMargin.Left * this.ScaleDpi);
                        int scale_navigation_button_right = (int)Math.Ceiling(this.TabBar.NavigationBar.ButtonLRMargin.Right * this.ScaleDpi);
                        Size scale_navigation_prev_button_size = Size.Ceiling(new SizeF(this.TabBar.NavigationBar.ButtonSize.Width * this.ScaleDpi, this.TabBar.NavigationBar.ButtonSize.Height * this.ScaleDpi));
                        Size scale_navigation_next_button_size = Size.Ceiling(new SizeF(this.TabBar.NavigationBar.ButtonSize.Width * this.ScaleDpi, this.TabBar.NavigationBar.ButtonSize.Height * this.ScaleDpi));

                        int scale_tabbar_navigation_btn_height_sum = 0;
                        scale_tabbar_navigation_btn_height_sum += scale_navigation_button_left + scale_navigation_prev_button_size.Width + scale_navigation_button_right;
                        scale_tabbar_navigation_btn_height_sum += scale_navigation_button_left + scale_navigation_next_button_size.Width + scale_navigation_button_right;

                        this.tabbar_navigationbar_c_rect = new Rectangle(this.tabbar_c_rect.X, this.tabbar_c_rect.Bottom - this.tabbar_globalbuttton_c_rect.Height - scale_tabbar_navigation_btn_height_sum, scale_tabbar_item_size.Height, scale_tabbar_navigation_btn_height_sum);

                        this.TabBar.NavigationBar.PrevButton.M_Rect = new Rectangle(this.tabbar_navigationbar_c_rect.X + (this.tabbar_navigationbar_c_rect.Width - scale_navigation_prev_button_size.Height) / 2, this.tabbar_navigationbar_c_rect.Y, scale_navigation_prev_button_size.Height, scale_navigation_button_left + scale_navigation_prev_button_size.Width + scale_navigation_button_right);
                        this.TabBar.NavigationBar.PrevButton.C_Rect = new Rectangle(this.TabBar.NavigationBar.PrevButton.M_Rect.X, this.TabBar.NavigationBar.PrevButton.M_Rect.Y + scale_navigation_button_left, scale_navigation_prev_button_size.Height, scale_navigation_prev_button_size.Width);

                        this.TabBar.NavigationBar.NextButton.M_Rect = new Rectangle(this.tabbar_navigationbar_c_rect.X + (this.tabbar_navigationbar_c_rect.Width - scale_navigation_next_button_size.Height) / 2, this.TabBar.NavigationBar.PrevButton.M_Rect.Bottom, scale_navigation_next_button_size.Height, scale_navigation_button_left + scale_navigation_next_button_size.Width + scale_navigation_button_right);
                        this.TabBar.NavigationBar.NextButton.C_Rect = new Rectangle(this.TabBar.NavigationBar.NextButton.M_Rect.X, this.TabBar.NavigationBar.NextButton.M_Rect.Y + scale_navigation_button_left, scale_navigation_next_button_size.Height, scale_navigation_next_button_size.Width);
                    }
                    else
                    {
                        this.tabbar_navigationbar_c_rect = new Rectangle(this.tabbar_c_rect.X, this.tabbar_c_rect.Bottom - this.tabbar_globalbuttton_c_rect.Height, scale_tabbar_item_size.Height, 0);
                        this.TabBar.NavigationBar.PrevButton.M_Rect = Rectangle.Empty;
                        this.TabBar.NavigationBar.PrevButton.C_Rect = Rectangle.Empty;
                        this.TabBar.NavigationBar.NextButton.M_Rect = Rectangle.Empty;
                        this.TabBar.NavigationBar.NextButton.C_Rect = Rectangle.Empty;
                    }
                }
                else
                {
                    if (this.TabBar.NavigationBar.Visible)
                    {
                        int scale_navigation_button_left = (int)Math.Ceiling(this.TabBar.NavigationBar.ButtonLRMargin.Left * this.ScaleDpi);
                        int scale_navigation_button_right = (int)Math.Ceiling(this.TabBar.NavigationBar.ButtonLRMargin.Right * this.ScaleDpi);
                        Size scale_navigation_prev_button_size = Size.Ceiling(new SizeF(this.TabBar.NavigationBar.ButtonSize.Width * this.ScaleDpi, this.TabBar.NavigationBar.ButtonSize.Height * this.ScaleDpi));
                        Size scale_navigation_next_button_size = Size.Ceiling(new SizeF(this.TabBar.NavigationBar.ButtonSize.Width * this.ScaleDpi, this.TabBar.NavigationBar.ButtonSize.Height * this.ScaleDpi));

                        int scale_tabbar_navigation_btn_width_sum = 0;
                        scale_tabbar_navigation_btn_width_sum += scale_navigation_button_left + scale_navigation_prev_button_size.Width + scale_navigation_button_right;
                        scale_tabbar_navigation_btn_width_sum += scale_navigation_button_left + scale_navigation_next_button_size.Width + scale_navigation_button_right;
                        int scale_navigation_btn_height_sum = scale_tabbar_item_size.Height;

                        this.tabbar_navigationbar_c_rect = new Rectangle(this.tabbar_c_rect.Right - this.tabbar_globalbuttton_c_rect.Width - scale_tabbar_navigation_btn_width_sum, this.tabbar_c_rect.Bottom - scale_navigation_btn_height_sum, scale_tabbar_navigation_btn_width_sum, scale_navigation_btn_height_sum);

                        this.TabBar.NavigationBar.PrevButton.M_Rect = new Rectangle(this.tabbar_navigationbar_c_rect.X, this.tabbar_navigationbar_c_rect.Y + (this.tabbar_navigationbar_c_rect.Height - scale_navigation_prev_button_size.Height) / 2, scale_navigation_button_left + scale_navigation_prev_button_size.Width + scale_navigation_button_right, scale_navigation_prev_button_size.Height);
                        this.TabBar.NavigationBar.PrevButton.C_Rect = new Rectangle(this.TabBar.NavigationBar.PrevButton.M_Rect.X + scale_navigation_button_left, this.TabBar.NavigationBar.PrevButton.M_Rect.Y, scale_navigation_prev_button_size.Width, scale_navigation_prev_button_size.Height);

                        this.TabBar.NavigationBar.NextButton.M_Rect = new Rectangle(this.TabBar.NavigationBar.PrevButton.M_Rect.Right, this.tabbar_navigationbar_c_rect.Y + (this.tabbar_navigationbar_c_rect.Height - scale_navigation_next_button_size.Height) / 2, scale_navigation_button_left + scale_navigation_next_button_size.Width + scale_navigation_button_right, scale_navigation_next_button_size.Height);
                        this.TabBar.NavigationBar.NextButton.C_Rect = new Rectangle(this.TabBar.NavigationBar.NextButton.M_Rect.X + scale_navigation_button_left, this.TabBar.NavigationBar.NextButton.M_Rect.Y, scale_navigation_next_button_size.Width, scale_navigation_next_button_size.Height);
                    }
                    else
                    {
                        this.tabbar_navigationbar_c_rect = new Rectangle(this.tabbar_c_rect.Right - this.tabbar_globalbuttton_c_rect.Width, this.tabbar_c_rect.Bottom, scale_tabbar_item_size.Width, 0);
                        this.TabBar.NavigationBar.PrevButton.M_Rect = Rectangle.Empty;
                        this.TabBar.NavigationBar.PrevButton.C_Rect = Rectangle.Empty;
                        this.TabBar.NavigationBar.NextButton.M_Rect = Rectangle.Empty;
                        this.TabBar.NavigationBar.NextButton.C_Rect = Rectangle.Empty;
                    }
                }
            }

            // 根据tabitem是否超出显示区边界来更新导航栏当前的显示状态
            if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Top || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Bottom)
            {
                float scale_tabbar_items_width_sum = 0;
                for (int i = 0; i < this.TabCount; i++)
                {
                    TabPagePlus tab_page = this.TabPages[i];
                    int scale_tabbar_item_left_margin = (int)Math.Ceiling(this.GetProperty_ItemLeftMargin(tab_page) * this.ScaleDpi);
                    int scale_tabbar_item_right_margin = (int)Math.Ceiling(this.GetProperty_ItemRightMargin(tab_page) * this.ScaleDpi);
                    int scale_tabbar_item_left_padding = (int)Math.Ceiling(this.GetProperty_ItemLeftPadding(tab_page) * this.ScaleDpi);
                    int scale_tabbar_item_right_padding = (int)Math.Ceiling(this.GetProperty_ItemRightPadding(tab_page) * this.ScaleDpi);
                    if (i == 0)
                    {
                        scale_tabbar_items_width_sum += scale_tabbar_item_left_padding + tab_page.Rect_C_Size.Width + scale_tabbar_item_right_padding + scale_tabbar_item_right_margin;
                    }
                    else if (i == this.TabCount - 1)
                    {
                        scale_tabbar_items_width_sum += scale_tabbar_item_left_margin + scale_tabbar_item_left_padding + tab_page.Rect_C_Size.Width + scale_tabbar_item_right_padding;
                    }
                    else
                    {
                        scale_tabbar_items_width_sum += scale_tabbar_item_left_margin + scale_tabbar_item_left_padding + tab_page.Rect_C_Size.Width + scale_tabbar_item_right_padding + scale_tabbar_item_right_margin;
                    }
                }

                if (this.TabCount > 0 && scale_tabbar_items_width_sum > this.tabbar_c_rect.Width - this.tabbar_globalbuttton_c_rect.Width)
                {
                    this.tabbar_navigationbar_visualstatus = true;
                }
                else
                {
                    this.tabbar_navigationbar_visualstatus = false;
                }
            }
            else if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Left || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Right)
            {
                if (this.TabBar.TabItem.VerticalLayout)
                {
                    float scale_tabbar_items_height_sum = 0;
                    for (int i = 0; i < this.TabCount; i++)
                    {
                        TabPagePlus tab_page = this.TabPages[i];
                        int scale_tabbar_item_left_margin = (int)Math.Ceiling(this.GetProperty_ItemLeftMargin(tab_page) * this.ScaleDpi);
                        int scale_tabbar_item_right_margin = (int)Math.Ceiling(this.GetProperty_ItemRightMargin(tab_page) * this.ScaleDpi);
                        int scale_tabbar_item_left_padding = (int)Math.Ceiling(this.GetProperty_ItemLeftPadding(tab_page) * this.ScaleDpi);
                        int scale_tabbar_item_right_padding = (int)Math.Ceiling(this.GetProperty_ItemRightPadding(tab_page) * this.ScaleDpi);
                        if (i == 0)
                        {
                            scale_tabbar_items_height_sum += scale_tabbar_item_left_padding + tab_page.Rect_C_Size.Width + scale_tabbar_item_right_padding + scale_tabbar_item_right_margin;
                        }
                        else if (i == this.TabCount - 1)
                        {
                            scale_tabbar_items_height_sum += scale_tabbar_item_left_margin + scale_tabbar_item_left_padding + tab_page.Rect_C_Size.Width + scale_tabbar_item_right_padding;
                        }
                        else
                        {
                            scale_tabbar_items_height_sum += scale_tabbar_item_left_margin + scale_tabbar_item_left_padding + tab_page.Rect_C_Size.Width + scale_tabbar_item_right_padding + scale_tabbar_item_right_margin;
                        }
                    }

                    if (this.TabCount > 0 && scale_tabbar_items_height_sum > this.tabbar_c_rect.Height - this.tabbar_globalbuttton_c_rect.Height)
                    {
                        this.tabbar_navigationbar_visualstatus = true;
                    }
                    else
                    {
                        this.tabbar_navigationbar_visualstatus = false;
                    }
                }
                else
                {
                    float scale_tabbar_items_height_sum = 0;
                    for (int i = 0; i < this.TabCount; i++)
                    {
                        TabPagePlus tab_page = this.TabPages[i];
                        int scale_tabbar_item_left_margin = (int)Math.Ceiling(this.GetProperty_ItemLeftMargin(tab_page) * this.ScaleDpi);
                        int scale_tabbar_item_right_margin = (int)Math.Ceiling(this.GetProperty_ItemRightMargin(tab_page) * this.ScaleDpi);
                        int scale_tabbar_item_left_padding = (int)Math.Ceiling(this.GetProperty_ItemLeftPadding(tab_page) * this.ScaleDpi);
                        int scale_tabbar_item_right_padding = (int)Math.Ceiling(this.GetProperty_ItemRightPadding(tab_page) * this.ScaleDpi);
                        if (i == 0)
                        {
                            scale_tabbar_items_height_sum += tab_page.Rect_C_Size.Height + scale_tabbar_item_right_margin;
                        }
                        else if (i == this.TabCount - 1)
                        {
                            scale_tabbar_items_height_sum += scale_tabbar_item_left_margin + tab_page.Rect_C_Size.Height;
                        }
                        else
                        {
                            scale_tabbar_items_height_sum += scale_tabbar_item_left_margin + tab_page.Rect_C_Size.Height + scale_tabbar_item_right_margin;
                        }
                    }

                    if (this.TabCount > 0 && scale_tabbar_items_height_sum > this.tabbar_c_rect.Height - this.tabbar_globalbuttton_c_rect.Height)
                    {
                        this.tabbar_navigationbar_visualstatus = true;
                    }
                    else
                    {
                        this.tabbar_navigationbar_visualstatus = false;
                    }
                }

            }

            // 更新TabItems的总显示区域Rectangle信息
            if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Top || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Bottom)
            {
                if (this.tabbar_navigationbar_visualstatus)
                {
                    this.tabbar_items_c_rect = new Rectangle(this.tabbar_c_rect.X, this.tabbar_c_rect.Y, this.tabbar_c_rect.Width - this.tabbar_globalbuttton_c_rect.Width - this.tabbar_navigationbar_c_rect.Width, this.tabbar_c_rect.Height);
                }
                else
                {
                    this.tabbar_items_c_rect = new Rectangle(this.tabbar_c_rect.X, this.tabbar_c_rect.Y, this.tabbar_c_rect.Width - this.tabbar_globalbuttton_c_rect.Width, this.tabbar_c_rect.Height);
                }

            }
            else if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Left || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Right)
            {
                if (this.TabBar.TabItem.VerticalLayout)
                {
                    if (this.tabbar_navigationbar_visualstatus)
                    {
                        this.tabbar_items_c_rect = new Rectangle(this.tabbar_c_rect.X, this.tabbar_c_rect.Y, this.tabbar_c_rect.Width, this.tabbar_c_rect.Height - this.tabbar_globalbuttton_c_rect.Height - this.tabbar_navigationbar_c_rect.Height);
                    }
                    else
                    {
                        this.tabbar_items_c_rect = new Rectangle(this.tabbar_c_rect.X, this.tabbar_c_rect.Y, this.tabbar_c_rect.Width, this.tabbar_c_rect.Height - this.tabbar_globalbuttton_c_rect.Height);
                    }
                }
                else
                {
                    if (this.tabbar_navigationbar_visualstatus || this.GetGlobalButttonVisualstatus())
                    {
                        this.tabbar_items_c_rect = new Rectangle(this.tabbar_c_rect.X, this.tabbar_c_rect.Y, this.tabbar_c_rect.Width, this.tabbar_c_rect.Height - this.tabbar_navigationbar_c_rect.Height);
                    }
                    else
                    {
                        this.tabbar_items_c_rect = new Rectangle(this.tabbar_c_rect.X, this.tabbar_c_rect.Y, this.tabbar_c_rect.Width, this.tabbar_c_rect.Height);
                    }
                }
            }

        }

        /// <summary>
        /// 根据ItemStartIndex更新每个TabItem的Rectangle信息
        /// </summary>
        internal void UpdateEveryOneTabItemRectangle()
        {
            Size scale_tabbar_item_size = Size.Ceiling(new SizeF(this.TabBar.TabItem.Size.Width * this.ScaleDpi, this.TabBar.TabItem.Size.Height * this.ScaleDpi));
            int scale_tabbar_item_rounded_lefttop = (int)Math.Ceiling(this.TabBar.TabItem.RoundSize.LeftTop * this.ScaleDpi);
            int scale_tabbar_item_rounded_righttop = (int)Math.Ceiling(this.TabBar.TabItem.RoundSize.RightTop * this.ScaleDpi);
            int scale_tabbar_item_rounded_leftbottom = (int)Math.Ceiling(this.TabBar.TabItem.RoundSize.LeftBottom * this.ScaleDpi);
            int scale_tabbar_item_rounded_rightbottom = (int)Math.Ceiling(this.TabBar.TabItem.RoundSize.RightBottom * this.ScaleDpi);
            int scale_tabbar_item_rounded_contentoffset = (int)Math.Ceiling(this.TabBar.TabItem.ContentOffset * this.ScaleDpi);

            Size scale_tabbar_item_ico_size = Size.Ceiling(new SizeF(this.TabBar.TabItem.Icon.Size.Width * this.ScaleDpi, this.TabBar.TabItem.Icon.Size.Height * this.ScaleDpi));
            int scale_tabbar_item_ico_left_margin = (int)Math.Ceiling(this.TabBar.TabItem.Icon.LRMargin.Left * this.ScaleDpi);
            int scale_tabbar_item_ico_right_margin = (int)Math.Ceiling(this.TabBar.TabItem.Icon.LRMargin.Right * this.ScaleDpi);

            TabControlPlusTabItemColseButtonAlignment tabbar_item_closebutton_alignments = this.TabBar.TabItem.CloseButton.Alignment;
            Size scale_tabbar_item_closebutton_size = Size.Ceiling(new SizeF(this.TabBar.TabItem.CloseButton.Size.Width * this.ScaleDpi, this.TabBar.TabItem.CloseButton.Size.Height * this.ScaleDpi));
            int scale_tabbar_item_closebutton_left_margin = (int)Math.Ceiling(this.TabBar.TabItem.CloseButton.LRMargin.Left * this.ScaleDpi);
            int scale_tabbar_item_closebutton_right_margin = (int)Math.Ceiling(this.TabBar.TabItem.CloseButton.LRMargin.Right * this.ScaleDpi);

            //计算正向选项rect
            for (int i = this.tabbar_items_start_index; i < this.TabCount; i++)
            {
                TabPagePlus tab_page = this.TabPages[i];

                int scale_tabbar_item_left_margin = (int)Math.Ceiling(this.GetProperty_ItemLeftMargin(tab_page) * this.ScaleDpi);
                int scale_tabbar_item_right_margin = (int)Math.Ceiling(this.GetProperty_ItemRightMargin(tab_page) * this.ScaleDpi);
                int scale_tabbar_item_left_padding = (int)Math.Ceiling(this.GetProperty_ItemLeftPadding(tab_page) * this.ScaleDpi);
                int scale_tabbar_item_right_padding = (int)Math.Ceiling(this.GetProperty_ItemRightPadding(tab_page) * this.ScaleDpi);

                if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Top || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Bottom)
                {
                    int tabbar_previtem_x = (i == tabbar_items_start_index) ? this.tabbar_c_rect.X - scale_tabbar_item_left_margin : this.TabPages[i - 1].M_Rect.Right;

                    tab_page.M_Rect = new Rectangle(tabbar_previtem_x, this.tabbar_c_rect.Y, scale_tabbar_item_left_margin + scale_tabbar_item_left_padding + tab_page.Rect_C_Size.Width + scale_tabbar_item_right_padding + scale_tabbar_item_right_margin, scale_tabbar_item_size.Height);
                    tab_page.P_Rect = new Rectangle(tab_page.M_Rect.X + scale_tabbar_item_left_margin, tab_page.M_Rect.Y, tab_page.M_Rect.Width - scale_tabbar_item_left_margin - scale_tabbar_item_right_margin, tab_page.M_Rect.Height);
                    tab_page.C_Rect = new Rectangle(tab_page.P_Rect.X + scale_tabbar_item_left_padding, tab_page.P_Rect.Y, tab_page.P_Rect.Width - scale_tabbar_item_left_padding - scale_tabbar_item_right_padding, tab_page.P_Rect.Height);
                }
                else if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Left || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Right)
                {
                    int tabbar_previtem_y = (i == tabbar_items_start_index) ? this.tabbar_c_rect.Y : this.TabPages[i - 1].M_Rect.Bottom;
                    if (this.TabBar.TabItem.VerticalLayout) //Tab选项是否纵向布局(限于左右两边)(依然存储横向的数据)
                    {
                        //选项rect
                        tab_page.M_Rect = new Rectangle(this.tabbar_c_rect.X, tabbar_previtem_y, scale_tabbar_item_size.Height, scale_tabbar_item_left_margin + scale_tabbar_item_left_padding + tab_page.Rect_C_Size.Width + scale_tabbar_item_right_padding + scale_tabbar_item_right_margin);
                        tab_page.P_Rect = new Rectangle(tab_page.M_Rect.X, tab_page.M_Rect.Y + scale_tabbar_item_left_margin, tab_page.M_Rect.Width, tab_page.M_Rect.Height - scale_tabbar_item_left_margin - scale_tabbar_item_right_margin);
                        tab_page.C_Rect = new Rectangle(tab_page.P_Rect.X, tab_page.P_Rect.Y + scale_tabbar_item_left_padding, tab_page.P_Rect.Width, tab_page.P_Rect.Height - scale_tabbar_item_left_padding - scale_tabbar_item_right_padding);
                    }
                    else
                    {
                        tab_page.M_Rect = new Rectangle(this.tabbar_c_rect.X, tabbar_previtem_y, scale_tabbar_item_size.Width, scale_tabbar_item_left_margin + scale_tabbar_item_size.Height + scale_tabbar_item_right_margin);
                        tab_page.P_Rect = new Rectangle(tab_page.M_Rect.X, tab_page.M_Rect.Y + scale_tabbar_item_left_margin, tab_page.M_Rect.Width, tab_page.M_Rect.Height - scale_tabbar_item_left_margin - scale_tabbar_item_right_margin);
                        tab_page.C_Rect = new Rectangle(tab_page.P_Rect.X + scale_tabbar_item_left_padding, tab_page.P_Rect.Y, tab_page.P_Rect.Width - scale_tabbar_item_left_padding - scale_tabbar_item_right_padding, tab_page.P_Rect.Height);
                    }
                }

                RectangleF item_p_rect_clip = new RectangleF(tab_page.P_Rect.X, tab_page.P_Rect.Y, tab_page.P_Rect.Width, tab_page.P_Rect.Height);
                item_p_rect_clip.Intersect(this.tabbar_items_c_rect);
                GraphicsPath tabbar_item_old_gp = tab_page.P_GP;
                TabControlPlusTabItemCreateCustomPathBeforeEventArgs arg = new TabControlPlusTabItemCreateCustomPathBeforeEventArgs(tab_page, this.ScaleDpi, this.tabbar_p_rect, this.tabbar_c_rect, this.tabbar_items_c_rect, tab_page.M_Rect, tab_page.P_Rect, tab_page.C_Rect, false);
                this.OnTabItemCreateCustomPathBefore(arg);
                if (arg.Cancel)
                {
                    tab_page.P_GP = arg.GraphicsPath;
                }
                else
                {
                    tab_page.P_GP = ControlHelper.AdjustCircularPath(tab_page.P_Rect, scale_tabbar_item_rounded_lefttop, scale_tabbar_item_rounded_righttop, scale_tabbar_item_rounded_rightbottom, scale_tabbar_item_rounded_leftbottom);
                }

                if (tabbar_item_old_gp != null)
                {
                    tabbar_item_old_gp.Dispose();
                }

            }

            //计算反向选项rect
            for (int i = this.tabbar_items_start_index - 1; i > -1; i--)
            {
                TabPagePlus tab_page = this.TabPages[i];

                int scale_tabbar_item_left_margin = this.GetProperty_ItemLeftMargin(tab_page);
                int scale_tabbar_item_right_margin = this.GetProperty_ItemRightMargin(tab_page);
                int scale_tabbar_item_left_padding = this.GetProperty_ItemLeftPadding(tab_page);
                int scale_tabbar_item_right_padding = this.GetProperty_ItemRightPadding(tab_page);

                if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Top || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Bottom)
                {
                    int scale_tabbar_item_m_width = scale_tabbar_item_left_margin + scale_tabbar_item_left_padding + tab_page.Rect_C_Size.Width + scale_tabbar_item_right_padding + scale_tabbar_item_right_margin;
                    tab_page.M_Rect = new Rectangle(this.TabPages[i + 1].M_Rect.X - scale_tabbar_item_m_width, this.tabbar_c_rect.Y, scale_tabbar_item_m_width, scale_tabbar_item_size.Height);
                    tab_page.P_Rect = new Rectangle(tab_page.M_Rect.X + scale_tabbar_item_left_margin, tab_page.M_Rect.Y, tab_page.M_Rect.Width - scale_tabbar_item_left_margin - scale_tabbar_item_right_margin, tab_page.M_Rect.Height);
                    tab_page.C_Rect = new Rectangle(tab_page.P_Rect.X + scale_tabbar_item_left_padding, tab_page.P_Rect.Y, tab_page.P_Rect.Width - scale_tabbar_item_left_padding - scale_tabbar_item_right_padding, tab_page.P_Rect.Height);
                }
                else if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Left || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Right)
                {
                    if (this.TabBar.TabItem.VerticalLayout) //Tab选项是否纵向布局(限于左右两边)(依然存储横向的数据)
                    {
                        int scale_tabbar_item_m_height = scale_tabbar_item_left_margin + scale_tabbar_item_left_padding + tab_page.Rect_C_Size.Width + scale_tabbar_item_right_padding + scale_tabbar_item_right_margin;
                        tab_page.M_Rect = new Rectangle(this.tabbar_c_rect.X, this.TabPages[i + 1].M_Rect.Y - scale_tabbar_item_m_height, scale_tabbar_item_size.Height, scale_tabbar_item_m_height);
                        tab_page.P_Rect = new Rectangle(tab_page.M_Rect.X, tab_page.M_Rect.Y + scale_tabbar_item_left_margin, tab_page.M_Rect.Width, tab_page.M_Rect.Height - scale_tabbar_item_left_margin - scale_tabbar_item_right_margin);
                        tab_page.C_Rect = new Rectangle(tab_page.P_Rect.X, tab_page.P_Rect.Y + scale_tabbar_item_left_padding, tab_page.P_Rect.Width, tab_page.P_Rect.Height - scale_tabbar_item_left_padding - scale_tabbar_item_right_padding);
                    }
                    else
                    {
                        int scale_tabbar_item_m_height = scale_tabbar_item_left_margin + scale_tabbar_item_size.Height + scale_tabbar_item_right_margin;
                        tab_page.M_Rect = new Rectangle(this.tabbar_c_rect.X, this.TabPages[i + 1].M_Rect.Y - scale_tabbar_item_m_height, scale_tabbar_item_size.Width, scale_tabbar_item_m_height);
                        tab_page.P_Rect = new Rectangle(tab_page.M_Rect.X, tab_page.M_Rect.Y + scale_tabbar_item_left_margin, tab_page.M_Rect.Width, tab_page.M_Rect.Height - scale_tabbar_item_left_margin - scale_tabbar_item_right_margin);
                        tab_page.C_Rect = new Rectangle(tab_page.P_Rect.X + scale_tabbar_item_left_padding, tab_page.M_Rect.Y, tab_page.P_Rect.Width - scale_tabbar_item_left_padding - scale_tabbar_item_right_padding, tab_page.P_Rect.Height);
                    }
                }


                RectangleF item_p_rect_clip = new RectangleF(tab_page.P_Rect.X, tab_page.P_Rect.Y, tab_page.P_Rect.Width, tab_page.P_Rect.Height);
                item_p_rect_clip.Intersect(this.tabbar_items_c_rect);
                GraphicsPath tabbar_item_old_gp = tab_page.P_GP;
                TabControlPlusTabItemCreateCustomPathBeforeEventArgs arg = new TabControlPlusTabItemCreateCustomPathBeforeEventArgs(tab_page, this.ScaleDpi, this.tabbar_p_rect, this.tabbar_c_rect, this.tabbar_items_c_rect, tab_page.M_Rect, tab_page.P_Rect, tab_page.C_Rect, false);
                this.OnTabItemCreateCustomPathBefore(arg);
                if (arg.Cancel)
                {
                    tab_page.P_GP = arg.GraphicsPath;
                }
                else
                {
                    tab_page.P_GP = ControlHelper.AdjustCircularPath(tab_page.P_Rect, scale_tabbar_item_rounded_lefttop, scale_tabbar_item_rounded_righttop, scale_tabbar_item_rounded_rightbottom, scale_tabbar_item_rounded_leftbottom);
                }

                if (tabbar_item_old_gp != null)
                {
                    tabbar_item_old_gp.Dispose();
                }

            }

            //计算选项内部部件rect
            for (int i = 0; i < this.TabCount; i++)
            {
                TabPagePlus tab_page = this.TabPages[i];

                bool tabbar_item_ico_visible = this.GetProperty_ItemIcoVisible(tab_page);
                bool tabbar_item_closebutton_visible = this.GetProperty_ItemColseVisible(tab_page);

                if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Top || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Bottom)
                {
                    if (tabbar_item_closebutton_alignments == TabControlPlusTabItemColseButtonAlignment.Left)
                    {
                        //选项关闭按钮rect
                        if (tabbar_item_closebutton_visible)
                        {
                            int scale_btn_m_width = scale_tabbar_item_closebutton_left_margin + scale_tabbar_item_closebutton_size.Width + scale_tabbar_item_closebutton_right_margin;
                            tab_page.TabItem.CloseButton.M_Rect = new Rectangle(tab_page.C_Rect.X, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - scale_tabbar_item_closebutton_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), scale_btn_m_width, scale_tabbar_item_closebutton_size.Height);
                            tab_page.TabItem.CloseButton.C_Rect = new Rectangle(tab_page.TabItem.CloseButton.M_Rect.X + scale_tabbar_item_closebutton_left_margin, tab_page.TabItem.CloseButton.M_Rect.Y, scale_tabbar_item_closebutton_size.Width, scale_tabbar_item_closebutton_size.Height);
                        }
                        else
                        {
                            tab_page.TabItem.CloseButton.M_Rect = new Rectangle(tab_page.C_Rect.X, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - scale_tabbar_item_closebutton_size.Height) / 2f) + scale_tabbar_item_rounded_contentoffset, 0, scale_tabbar_item_closebutton_size.Height);
                            tab_page.TabItem.CloseButton.C_Rect = tab_page.TabItem.CloseButton.M_Rect;
                        }

                        //选项自定义按钮rect
                        int item_custombuttons_x = tab_page.TabItem.CloseButton.M_Rect.Right;
                        for (int k = 0; k < tab_page.TabItem.CustomButtons.Count; k++)
                        {
                            TabControlPlusTabItemCustomButton btn = tab_page.TabItem.CustomButtons[k];
                            Size scale_btn_size = Size.Ceiling(new SizeF(btn.Size.Width * this.ScaleDpi, btn.Size.Height * this.ScaleDpi));
                            int scale_btn_margin_left = (int)Math.Ceiling(btn.LRMargin.Left * this.ScaleDpi);
                            int scale_btn_margin_right = (int)Math.Ceiling(btn.LRMargin.Right * this.ScaleDpi);

                            if (btn.Visible)
                            {
                                int scale_btn_m_width = scale_btn_margin_left + scale_btn_size.Width + scale_btn_margin_right;
                                btn.M_Rect = new Rectangle(item_custombuttons_x, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - scale_btn_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), scale_btn_m_width, scale_btn_size.Height);
                                btn.C_Rect = new Rectangle(btn.M_Rect.X + scale_btn_margin_left, btn.M_Rect.Y, scale_btn_size.Width, scale_btn_size.Height);
                                item_custombuttons_x = btn.M_Rect.Right;
                            }
                            else
                            {
                                btn.M_Rect = new Rectangle(item_custombuttons_x, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - scale_btn_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), 0, scale_btn_size.Height);
                                btn.C_Rect = btn.M_Rect;
                                item_custombuttons_x = btn.M_Rect.Right;
                            }
                        }

                        //选项文本rect
                        tab_page.Text_C_Rect = new Rectangle(item_custombuttons_x, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - tab_page.Text_C_Size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), tab_page.Text_C_Size.Width, tab_page.Text_C_Size.Height);

                        //选项图标rect
                        if (tabbar_item_ico_visible)
                        {
                            int scale_btn_m_width = scale_tabbar_item_ico_left_margin + scale_tabbar_item_ico_size.Width + scale_tabbar_item_ico_right_margin;
                            tab_page.Icon_M_Rect = new Rectangle(tab_page.Text_C_Rect.Right, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - scale_tabbar_item_ico_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), scale_btn_m_width, scale_tabbar_item_ico_size.Height);
                            tab_page.Icon_C_Rect = new Rectangle(tab_page.Icon_M_Rect.X + scale_tabbar_item_ico_left_margin, tab_page.Icon_M_Rect.Y, scale_tabbar_item_ico_size.Width, scale_tabbar_item_ico_size.Height);
                        }
                        else
                        {
                            tab_page.Icon_M_Rect = new Rectangle(tab_page.Text_C_Rect.Right, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - scale_tabbar_item_ico_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), 0, scale_tabbar_item_ico_size.Height);
                            tab_page.Icon_C_Rect = tab_page.Icon_M_Rect;
                        }

                    }
                    else if (tabbar_item_closebutton_alignments == TabControlPlusTabItemColseButtonAlignment.Right)
                    {
                        //选项关闭按钮rect
                        if (tabbar_item_closebutton_visible)
                        {
                            int scale_btn_m_width = scale_tabbar_item_closebutton_left_margin + scale_tabbar_item_closebutton_size.Width + scale_tabbar_item_closebutton_right_margin;
                            tab_page.TabItem.CloseButton.M_Rect = new Rectangle(tab_page.C_Rect.Right - scale_btn_m_width, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - scale_tabbar_item_closebutton_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), scale_btn_m_width, scale_tabbar_item_closebutton_size.Height);
                            tab_page.TabItem.CloseButton.C_Rect = new Rectangle(tab_page.TabItem.CloseButton.M_Rect.X + scale_tabbar_item_closebutton_left_margin, tab_page.TabItem.CloseButton.M_Rect.Y, scale_tabbar_item_closebutton_size.Width, scale_tabbar_item_closebutton_size.Height);
                        }
                        else
                        {
                            tab_page.TabItem.CloseButton.M_Rect = new Rectangle(tab_page.C_Rect.Right, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - scale_tabbar_item_closebutton_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), 0, scale_tabbar_item_closebutton_size.Height);
                            tab_page.TabItem.CloseButton.C_Rect = tab_page.TabItem.CloseButton.M_Rect;
                        }

                        //选项自定义按钮rect
                        int item_custombuttons_x = tab_page.TabItem.CloseButton.M_Rect.X;
                        for (int k = tab_page.TabItem.CustomButtons.Count - 1; k > -1; k--)
                        {
                            TabControlPlusTabItemCustomButton btn = tab_page.TabItem.CustomButtons[k];
                            Size scale_btn_size = Size.Ceiling(new SizeF(btn.Size.Width * this.ScaleDpi, btn.Size.Height * this.ScaleDpi));
                            int scale_btn_margin_left = (int)Math.Ceiling(btn.LRMargin.Left * this.ScaleDpi);
                            int scale_btn_margin_right = (int)Math.Ceiling(btn.LRMargin.Right * this.ScaleDpi);

                            if (btn.Visible)
                            {
                                int scale_btn_m_width = scale_btn_margin_left + scale_btn_size.Width + scale_btn_margin_right;
                                btn.M_Rect = new Rectangle(item_custombuttons_x - scale_btn_m_width, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - scale_btn_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), scale_btn_m_width, scale_btn_size.Height);
                                btn.C_Rect = new Rectangle(btn.M_Rect.X + scale_btn_margin_left, btn.M_Rect.Y, scale_btn_size.Width, scale_btn_size.Height);
                                item_custombuttons_x = btn.M_Rect.X;
                            }
                            else
                            {
                                btn.M_Rect = new Rectangle(item_custombuttons_x, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - scale_btn_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), 0, scale_btn_size.Height);
                                btn.C_Rect = btn.M_Rect;
                                item_custombuttons_x = btn.M_Rect.X;
                            }
                        }

                        //选项文本rect
                        tab_page.Text_C_Rect = new Rectangle(item_custombuttons_x - tab_page.Text_C_Size.Width, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - tab_page.Text_C_Size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), tab_page.Text_C_Size.Width, tab_page.Text_C_Size.Height);

                        //选项图标rect
                        if (tabbar_item_ico_visible)
                        {
                            int scale_btn_m_width = scale_tabbar_item_ico_left_margin + scale_tabbar_item_ico_size.Width + scale_tabbar_item_ico_right_margin;
                            tab_page.Icon_M_Rect = new Rectangle(tab_page.Text_C_Rect.X - scale_btn_m_width, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - scale_tabbar_item_ico_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), scale_btn_m_width, scale_tabbar_item_ico_size.Height);
                            tab_page.Icon_C_Rect = new Rectangle(tab_page.Icon_M_Rect.X + scale_tabbar_item_ico_left_margin, tab_page.Icon_M_Rect.Y, scale_tabbar_item_ico_size.Width, scale_tabbar_item_ico_size.Height);
                        }
                        else
                        {
                            tab_page.Icon_M_Rect = new Rectangle(tab_page.Text_C_Rect.X, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - scale_tabbar_item_ico_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), 0, scale_tabbar_item_ico_size.Height);
                            tab_page.Icon_C_Rect = tab_page.Icon_M_Rect;
                        }

                    }
                }
                else if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Left || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Right)
                {
                    if (this.TabBar.TabItem.VerticalLayout) //Tab选项是否纵向布局(限于左右两边)(依然存储横向的数据)
                    {
                        if (tabbar_item_closebutton_alignments == TabControlPlusTabItemColseButtonAlignment.Left)
                        {
                            //选项关闭按钮rect
                            if (tabbar_item_closebutton_visible)
                            {
                                int scale_btn_m_width = scale_tabbar_item_closebutton_left_margin + scale_tabbar_item_closebutton_size.Width + scale_tabbar_item_closebutton_right_margin;
                                tab_page.TabItem.CloseButton.M_Rect = new Rectangle((int)Math.Ceiling(tab_page.C_Rect.X + (tab_page.C_Rect.Width - scale_tabbar_item_closebutton_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), tab_page.C_Rect.Y, scale_tabbar_item_closebutton_size.Height, scale_btn_m_width);
                                tab_page.TabItem.CloseButton.C_Rect = new Rectangle(tab_page.TabItem.CloseButton.M_Rect.X, tab_page.TabItem.CloseButton.M_Rect.Y + scale_tabbar_item_closebutton_left_margin, scale_tabbar_item_closebutton_size.Height, scale_tabbar_item_closebutton_size.Width);
                            }
                            else
                            {
                                tab_page.TabItem.CloseButton.M_Rect = new Rectangle((int)Math.Ceiling(tab_page.C_Rect.X + (tab_page.C_Rect.Width - scale_tabbar_item_closebutton_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), tab_page.C_Rect.Y, scale_tabbar_item_closebutton_size.Height, 0);
                                tab_page.TabItem.CloseButton.C_Rect = tab_page.TabItem.CloseButton.M_Rect;
                            }

                            //选项自定义按钮rect
                            int item_custombuttons_y = tab_page.TabItem.CloseButton.M_Rect.Bottom;
                            for (int k = 0; k < tab_page.TabItem.CustomButtons.Count; k++)
                            {
                                TabControlPlusTabItemCustomButton btn = tab_page.TabItem.CustomButtons[k];
                                Size scale_btn_size = Size.Ceiling(new SizeF(btn.Size.Width * this.ScaleDpi, btn.Size.Height * this.ScaleDpi));
                                int scale_btn_margin_left = (int)Math.Ceiling(btn.LRMargin.Left * this.ScaleDpi);
                                int scale_btn_margin_right = (int)Math.Ceiling(btn.LRMargin.Right * this.ScaleDpi);

                                if (btn.Visible)
                                {
                                    int scale_btn_m_width = scale_btn_margin_left + scale_btn_size.Width + scale_btn_margin_right;
                                    btn.M_Rect = new Rectangle((int)Math.Ceiling(tab_page.C_Rect.X + (tab_page.C_Rect.Width - scale_btn_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), item_custombuttons_y, scale_btn_size.Height, scale_btn_m_width);
                                    btn.C_Rect = new Rectangle(btn.M_Rect.X, btn.M_Rect.Y + scale_btn_margin_left, scale_btn_size.Height, scale_btn_size.Width);
                                    item_custombuttons_y = btn.M_Rect.Bottom;
                                }
                                else
                                {
                                    btn.M_Rect = new Rectangle((int)Math.Ceiling(tab_page.C_Rect.X + (tab_page.C_Rect.Width - scale_btn_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), item_custombuttons_y, scale_btn_size.Height, 0);
                                    btn.C_Rect = btn.M_Rect;
                                    item_custombuttons_y = btn.M_Rect.Bottom;
                                }
                            }

                            tab_page.Text_C_Rect = new Rectangle((int)Math.Ceiling(tab_page.C_Rect.X + (tab_page.C_Rect.Width - tab_page.Text_C_Size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), item_custombuttons_y, tab_page.Text_C_Size.Height, tab_page.Text_C_Size.Width);

                            //选项图标rect
                            if (tabbar_item_ico_visible)
                            {
                                int scale_btn_m_width = scale_tabbar_item_ico_left_margin + scale_tabbar_item_ico_size.Width + scale_tabbar_item_ico_right_margin;
                                tab_page.Icon_M_Rect = new Rectangle((int)Math.Ceiling(tab_page.C_Rect.X + (tab_page.C_Rect.Width - scale_tabbar_item_ico_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), tab_page.Text_C_Rect.Bottom, scale_tabbar_item_ico_size.Height, scale_btn_m_width);
                                tab_page.Icon_C_Rect = new Rectangle(tab_page.Icon_M_Rect.X, tab_page.Icon_M_Rect.Y + scale_tabbar_item_ico_left_margin, scale_tabbar_item_ico_size.Height, scale_tabbar_item_ico_size.Width);
                            }
                            else
                            {
                                tab_page.Icon_M_Rect = new Rectangle((int)Math.Ceiling(tab_page.C_Rect.X + (tab_page.C_Rect.Width - scale_tabbar_item_ico_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), tab_page.Text_C_Rect.Bottom, scale_tabbar_item_ico_size.Height, 0);
                                tab_page.Icon_C_Rect = tab_page.Icon_M_Rect;
                            }

                        }
                        else if (tabbar_item_closebutton_alignments == TabControlPlusTabItemColseButtonAlignment.Right)
                        {
                            //选项关闭按钮rect
                            if (tabbar_item_closebutton_visible)
                            {
                                int scale_btn_m_width = scale_tabbar_item_closebutton_left_margin + scale_tabbar_item_closebutton_size.Width + scale_tabbar_item_closebutton_right_margin;
                                tab_page.TabItem.CloseButton.M_Rect = new Rectangle((int)Math.Ceiling(tab_page.C_Rect.X + (tab_page.C_Rect.Width - scale_tabbar_item_closebutton_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), tab_page.C_Rect.Bottom - scale_btn_m_width, scale_tabbar_item_closebutton_size.Height, scale_btn_m_width);
                                tab_page.TabItem.CloseButton.C_Rect = new Rectangle(tab_page.TabItem.CloseButton.M_Rect.X, tab_page.TabItem.CloseButton.M_Rect.Y + scale_tabbar_item_closebutton_left_margin, scale_tabbar_item_closebutton_size.Height, scale_tabbar_item_closebutton_size.Width);
                            }
                            else
                            {
                                tab_page.TabItem.CloseButton.M_Rect = new Rectangle((int)Math.Ceiling(tab_page.C_Rect.X + (tab_page.C_Rect.Width - scale_tabbar_item_closebutton_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), tab_page.C_Rect.Bottom, scale_tabbar_item_closebutton_size.Height, 0);
                                tab_page.TabItem.CloseButton.C_Rect = tab_page.TabItem.CloseButton.M_Rect;
                            }

                            //选项自定义按钮rect
                            int item_custombuttons_y = tab_page.TabItem.CloseButton.M_Rect.Y;
                            for (int k = tab_page.TabItem.CustomButtons.Count - 1; k > -1; k--)
                            {
                                TabControlPlusTabItemCustomButton btn = tab_page.TabItem.CustomButtons[k];
                                Size scale_btn_size = Size.Ceiling(new SizeF(btn.Size.Width * this.ScaleDpi, btn.Size.Height * this.ScaleDpi));
                                int scale_btn_margin_left = (int)Math.Ceiling(btn.LRMargin.Left * this.ScaleDpi);
                                int scale_btn_margin_right = (int)Math.Ceiling(btn.LRMargin.Right * this.ScaleDpi);

                                if (btn.Visible)
                                {
                                    int scale_btn_m_width = scale_btn_margin_left + scale_btn_size.Width + scale_btn_margin_right;
                                    btn.M_Rect = new Rectangle((int)Math.Ceiling(tab_page.C_Rect.X + (tab_page.C_Rect.Width - scale_btn_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), item_custombuttons_y - scale_btn_m_width, scale_btn_size.Height, scale_btn_m_width);
                                    btn.C_Rect = new Rectangle(btn.M_Rect.X, btn.M_Rect.Y + scale_btn_margin_left, scale_btn_size.Height, scale_btn_size.Width);
                                    item_custombuttons_y = btn.M_Rect.Y;
                                }
                                else
                                {
                                    btn.M_Rect = new Rectangle((int)Math.Ceiling(tab_page.C_Rect.X + (tab_page.C_Rect.Width - scale_btn_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), item_custombuttons_y, scale_btn_size.Height, 0);
                                    btn.C_Rect = btn.M_Rect;
                                    item_custombuttons_y = btn.M_Rect.Y;
                                }
                            }

                            //选项文本rect
                            tab_page.Text_C_Rect = new Rectangle((int)Math.Ceiling(tab_page.C_Rect.X + (tab_page.C_Rect.Width - tab_page.Text_C_Size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), item_custombuttons_y - tab_page.Text_C_Size.Width, tab_page.Text_C_Size.Height, tab_page.Text_C_Size.Width);

                            //选项图标rect
                            if (tabbar_item_ico_visible)
                            {
                                int scale_btn_m_width = scale_tabbar_item_ico_left_margin + scale_tabbar_item_ico_size.Width + scale_tabbar_item_ico_right_margin;
                                tab_page.Icon_M_Rect = new Rectangle((int)Math.Ceiling(tab_page.C_Rect.X + (tab_page.C_Rect.Width - scale_tabbar_item_ico_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), tab_page.Text_C_Rect.Y - scale_btn_m_width, scale_tabbar_item_ico_size.Height, scale_btn_m_width);
                                tab_page.Icon_C_Rect = new Rectangle(tab_page.Icon_M_Rect.X, tab_page.Icon_M_Rect.Y + scale_tabbar_item_ico_left_margin, scale_tabbar_item_ico_size.Height, scale_tabbar_item_ico_size.Width);
                            }
                            else
                            {
                                tab_page.Icon_M_Rect = new Rectangle((int)Math.Ceiling(tab_page.C_Rect.X + (tab_page.C_Rect.Width - scale_tabbar_item_ico_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), tab_page.Text_C_Rect.Y, scale_tabbar_item_ico_size.Height, 0);
                                tab_page.Icon_C_Rect = tab_page.Icon_M_Rect;
                            }

                        }
                    }
                    else
                    {
                        if (tabbar_item_closebutton_alignments == TabControlPlusTabItemColseButtonAlignment.Left)
                        {
                            //选项关闭按钮rect
                            if (tabbar_item_closebutton_visible)
                            {
                                int scale_btn_m_width = scale_tabbar_item_closebutton_left_margin + scale_tabbar_item_closebutton_size.Width + scale_tabbar_item_closebutton_right_margin;
                                tab_page.TabItem.CloseButton.M_Rect = new Rectangle(tab_page.C_Rect.X, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - scale_tabbar_item_closebutton_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), scale_btn_m_width, scale_tabbar_item_closebutton_size.Height);
                                tab_page.TabItem.CloseButton.C_Rect = new Rectangle(tab_page.TabItem.CloseButton.M_Rect.X + scale_tabbar_item_closebutton_left_margin, tab_page.TabItem.CloseButton.M_Rect.Y, scale_tabbar_item_closebutton_size.Width, scale_tabbar_item_closebutton_size.Height);
                            }
                            else
                            {
                                tab_page.TabItem.CloseButton.M_Rect = new Rectangle(tab_page.C_Rect.X, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - scale_tabbar_item_closebutton_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), 0, scale_tabbar_item_closebutton_size.Height);
                                tab_page.TabItem.CloseButton.C_Rect = tab_page.TabItem.CloseButton.M_Rect;
                            }

                            //选项自定义按钮rect
                            int item_custombuttons_x = tab_page.TabItem.CloseButton.M_Rect.Right;
                            for (int k = 0; k < tab_page.TabItem.CustomButtons.Count; k++)
                            {
                                TabControlPlusTabItemCustomButton btn = tab_page.TabItem.CustomButtons[k];
                                Size scale_btn_size = Size.Ceiling(new SizeF(btn.Size.Width * this.ScaleDpi, btn.Size.Height * this.ScaleDpi));
                                int scale_btn_margin_left = (int)Math.Ceiling(btn.LRMargin.Left * this.ScaleDpi);
                                int scale_btn_margin_right = (int)Math.Ceiling(btn.LRMargin.Right * this.ScaleDpi);

                                if (btn.Visible)
                                {
                                    int scale_btn_m_width = scale_btn_margin_left + scale_btn_size.Width + scale_btn_margin_right;
                                    btn.M_Rect = new Rectangle(item_custombuttons_x, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - scale_btn_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), scale_btn_m_width, scale_btn_size.Height);
                                    btn.C_Rect = new Rectangle(btn.M_Rect.X + scale_btn_margin_left, btn.M_Rect.Y, scale_btn_size.Width, scale_btn_size.Height);
                                    item_custombuttons_x = btn.M_Rect.Right;
                                }
                                else
                                {
                                    btn.M_Rect = new Rectangle(item_custombuttons_x, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - scale_btn_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), 0, scale_btn_size.Height);
                                    btn.C_Rect = btn.M_Rect;
                                    item_custombuttons_x = btn.M_Rect.Right;
                                }
                            }

                            //选项文本rect
                            tab_page.Text_C_Rect = new Rectangle(item_custombuttons_x, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - tab_page.Text_C_Size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), tab_page.Text_C_Size.Width, tab_page.Text_C_Size.Height);

                            //选项图标rect
                            if (tabbar_item_ico_visible)
                            {
                                int scale_btn_m_width = scale_tabbar_item_ico_left_margin + scale_tabbar_item_ico_size.Width + scale_tabbar_item_ico_right_margin;
                                tab_page.Icon_M_Rect = new Rectangle(tab_page.Text_C_Rect.Right, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - scale_tabbar_item_ico_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), scale_btn_m_width, scale_tabbar_item_ico_size.Height);
                                tab_page.Icon_C_Rect = new Rectangle(tab_page.Icon_M_Rect.X + scale_tabbar_item_ico_left_margin, tab_page.Icon_M_Rect.Y, scale_tabbar_item_ico_size.Width, scale_tabbar_item_ico_size.Height);
                            }
                            else
                            {
                                tab_page.Icon_M_Rect = new Rectangle(tab_page.Text_C_Rect.Right, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - scale_tabbar_item_ico_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), 0, scale_tabbar_item_ico_size.Height);
                                tab_page.Icon_C_Rect = tab_page.Icon_M_Rect;
                            }

                        }
                        else if (tabbar_item_closebutton_alignments == TabControlPlusTabItemColseButtonAlignment.Right)
                        {
                            //选项关闭按钮rect
                            if (tabbar_item_closebutton_visible)
                            {
                                int scale_btn_m_width = scale_tabbar_item_closebutton_left_margin + scale_tabbar_item_closebutton_size.Width + scale_tabbar_item_closebutton_right_margin;
                                tab_page.TabItem.CloseButton.M_Rect = new Rectangle(tab_page.C_Rect.Right - scale_btn_m_width, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - scale_tabbar_item_closebutton_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), scale_btn_m_width, scale_tabbar_item_closebutton_size.Height);
                                tab_page.TabItem.CloseButton.C_Rect = new Rectangle(tab_page.TabItem.CloseButton.M_Rect.X + scale_tabbar_item_closebutton_left_margin, tab_page.TabItem.CloseButton.M_Rect.Y, scale_tabbar_item_closebutton_size.Width, scale_tabbar_item_closebutton_size.Height);
                            }
                            else
                            {
                                tab_page.TabItem.CloseButton.M_Rect = new Rectangle(tab_page.C_Rect.Right, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - scale_tabbar_item_closebutton_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), 0, scale_tabbar_item_closebutton_size.Height);
                                tab_page.TabItem.CloseButton.C_Rect = tab_page.TabItem.CloseButton.M_Rect;
                            }

                            //选项自定义按钮rect
                            int item_custombuttons_x = tab_page.TabItem.CloseButton.M_Rect.X;
                            for (int k = tab_page.TabItem.CustomButtons.Count - 1; k > -1; k--)
                            {
                                TabControlPlusTabItemCustomButton btn = tab_page.TabItem.CustomButtons[k];
                                Size scale_btn_size = Size.Ceiling(new SizeF(btn.Size.Width * this.ScaleDpi, btn.Size.Height * this.ScaleDpi));
                                int scale_btn_margin_left = (int)Math.Ceiling(btn.LRMargin.Left * this.ScaleDpi);
                                int scale_btn_margin_right = (int)Math.Ceiling(btn.LRMargin.Right * this.ScaleDpi);

                                if (btn.Visible)
                                {
                                    int scale_btn_m_width = scale_btn_margin_left + scale_btn_size.Width + scale_btn_margin_right;
                                    btn.M_Rect = new Rectangle(item_custombuttons_x - scale_btn_m_width, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - scale_btn_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), scale_btn_m_width, scale_btn_size.Height);
                                    btn.C_Rect = new Rectangle(btn.M_Rect.X + scale_btn_margin_left, btn.M_Rect.Y, scale_btn_size.Width, scale_btn_size.Height);
                                    item_custombuttons_x = btn.M_Rect.X;
                                }
                                else
                                {
                                    btn.M_Rect = new Rectangle(item_custombuttons_x, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - scale_btn_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), 0, scale_btn_size.Height);
                                    btn.C_Rect = btn.M_Rect;
                                    item_custombuttons_x = btn.M_Rect.X;
                                }
                            }

                            //选项文本rect
                            tab_page.Text_C_Rect = new Rectangle(item_custombuttons_x - tab_page.Text_C_Size.Width, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - tab_page.Text_C_Size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), tab_page.Text_C_Size.Width, tab_page.Text_C_Size.Height);

                            //选项图标rect
                            if (tabbar_item_ico_visible)
                            {
                                int scale_btn_m_width = scale_tabbar_item_ico_left_margin + scale_tabbar_item_ico_size.Width + scale_tabbar_item_ico_right_margin;
                                tab_page.Icon_M_Rect = new Rectangle(tab_page.Text_C_Rect.X - scale_btn_m_width, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - scale_tabbar_item_ico_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), scale_btn_m_width, scale_tabbar_item_ico_size.Height);
                                tab_page.Icon_C_Rect = new Rectangle(tab_page.Icon_M_Rect.X + scale_tabbar_item_ico_left_margin, tab_page.Icon_M_Rect.Y, scale_tabbar_item_ico_size.Width, scale_tabbar_item_ico_size.Height);
                            }
                            else
                            {
                                tab_page.Icon_M_Rect = new Rectangle(tab_page.Text_C_Rect.X, (int)Math.Ceiling(tab_page.C_Rect.Y + (tab_page.C_Rect.Height - scale_tabbar_item_ico_size.Height) / 2f + scale_tabbar_item_rounded_contentoffset), 0, scale_tabbar_item_ico_size.Height);
                                tab_page.Icon_C_Rect = tab_page.Icon_M_Rect;
                            }

                        }
                    }
                }
            }

        }

        /// <summary>
        /// 自动把左边需要显示tabitem显示在tabitem总显示区域中
        /// </summary>
        private void ReplenishTabItemToRectangleForLeft()
        {
            if (this.tabbar_items_start_index > 0)
            {
                if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Top || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Bottom)
                {
                    if (this.TabPages[this.TabCount - 1].P_Rect.Right < this.tabbar_items_c_rect.Right)
                    {
                        int index_tmp = Math.Max(0, this.tabbar_items_start_index - 1);
                        for (int i = this.tabbar_items_start_index - 1; i >= 0; i--)
                        {
                            int scale_item_margin_left = (int)Math.Ceiling(this.GetProperty_ItemLeftMargin(this.TabPages[this.tabbar_items_start_index]) * this.ScaleDpi);
                            if (Math.Abs(this.TabPages[i].P_Rect.X) + scale_item_margin_left + this.TabPages[this.TabCount - 1].P_Rect.Right < this.tabbar_items_c_rect.Right)
                            {
                                index_tmp--;
                                continue;
                            }
                            break;
                        }

                        index_tmp = Math.Max(0, index_tmp);
                        this.tabbar_items_start_index = index_tmp;
                        this.UpdateEveryOneTabItemRectangle();
                    }

                }
                else if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Left || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Right)
                {
                    if (this.TabPages[this.TabCount - 1].P_Rect.Bottom < this.tabbar_items_c_rect.Bottom)
                    {
                        int index_tmp = Math.Max(0, this.tabbar_items_start_index - 1);
                        for (int i = this.tabbar_items_start_index - 1; i >= 0; i--)
                        {
                            int scale_item_margin_left = (int)Math.Ceiling(this.GetProperty_ItemLeftMargin(this.TabPages[this.tabbar_items_start_index]) * this.ScaleDpi);
                            if (Math.Abs(this.TabPages[i].P_Rect.Y) + scale_item_margin_left + this.TabPages[this.TabCount - 1].P_Rect.Bottom < this.tabbar_items_c_rect.Bottom)
                            {
                                index_tmp--;
                                continue;
                            }
                            break;
                        }

                        index_tmp = Math.Max(0, index_tmp);
                        this.tabbar_items_start_index = index_tmp;
                        this.UpdateEveryOneTabItemRectangle();
                    }
                }

            }
        }

        /// <summary>
        /// 自动把已选中tabitem显示在tabitem总显示区域中
        /// </summary>
        private void ReplenishSelectTabItemToRectangle()
        {
            if (this.SelectedIndex > -1)
            {
                if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Top || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Bottom)
                {
                    if (this.TabPages[this.SelectedIndex].P_Rect.X >= this.tabbar_items_c_rect.Right)
                    {
                        int index_tmp = Math.Min(this.TabCount - 1, this.tabbar_items_start_index + 1);
                        for (int i = this.tabbar_items_start_index + 1; i < this.TabCount; i++)
                        {
                            if (this.TabPages[this.SelectedIndex].P_Rect.X - this.TabPages[i].M_Rect.Width >= this.tabbar_items_c_rect.Right)
                            {
                                index_tmp++;
                                continue;
                            }
                            break;
                        }

                        index_tmp = Math.Min(this.TabCount - 1, index_tmp);
                        this.tabbar_items_start_index = index_tmp;
                        this.UpdateEveryOneTabItemRectangle();
                    }
                    else if (this.TabPages[this.SelectedIndex].P_Rect.Y < this.tabbar_items_c_rect.Y)
                    {
                        int index_tmp = Math.Max(0, this.tabbar_items_start_index - 1);
                        for (int i = this.tabbar_items_start_index - 1; i >= 0; i--)
                        {
                            if (this.TabPages[this.SelectedIndex].P_Rect.Y + Math.Abs(this.TabPages[i].M_Rect.Y) < this.tabbar_items_c_rect.Y)
                            {
                                index_tmp--;
                                continue;
                            }
                            break;
                        }

                        index_tmp = Math.Max(0, index_tmp);
                        this.tabbar_items_start_index = index_tmp;
                        this.UpdateEveryOneTabItemRectangle();
                    }
                    if (this.TabPages[this.SelectedIndex].P_Rect.X < this.tabbar_items_c_rect.X)
                    {
                        int index_tmp = Math.Max(0, this.tabbar_items_start_index - 1);
                        for (int i = this.tabbar_items_start_index - 1; i >= 0; i--)
                        {
                            if (this.TabPages[this.SelectedIndex].P_Rect.X + Math.Abs(this.TabPages[i].M_Rect.X) < this.tabbar_items_c_rect.X)
                            {
                                index_tmp--;
                                continue;
                            }
                            break;
                        }

                        index_tmp = Math.Max(0, index_tmp);
                        this.tabbar_items_start_index = index_tmp;
                        this.UpdateEveryOneTabItemRectangle();
                    }
                }
                else if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Left || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Right)
                {
                    if (this.TabPages[this.SelectedIndex].P_Rect.Y >= this.tabbar_items_c_rect.Bottom)
                    {
                        int index_tmp = Math.Min(this.TabCount - 1, this.tabbar_items_start_index + 1);
                        for (int i = this.tabbar_items_start_index + 1; i < this.TabCount; i++)
                        {
                            if (this.TabPages[this.SelectedIndex].P_Rect.Y - this.TabPages[i].M_Rect.Height >= this.tabbar_items_c_rect.Bottom)
                            {
                                index_tmp++;
                                continue;
                            }
                            break;
                        }

                        index_tmp = Math.Min(this.TabCount - 1, index_tmp);
                        this.tabbar_items_start_index = index_tmp;
                        this.UpdateEveryOneTabItemRectangle();
                    }

                    else if (this.TabPages[this.SelectedIndex].P_Rect.Y < this.tabbar_items_c_rect.Y)
                    {
                        int index_tmp = Math.Max(0, this.tabbar_items_start_index - 1);
                        for (int i = this.tabbar_items_start_index - 1; i >= 0; i--)
                        {
                            if (this.TabPages[this.SelectedIndex].P_Rect.Y + Math.Abs(this.TabPages[i].M_Rect.Y) < this.tabbar_items_c_rect.Y)
                            {
                                index_tmp--;
                                continue;
                            }
                            break;
                        }

                        index_tmp = Math.Max(0, index_tmp);
                        this.tabbar_items_start_index = index_tmp;
                        this.UpdateEveryOneTabItemRectangle();
                    }
                }
            }
        }

        /// <summary>
        /// 根据tabitems总显示区更新主体Rectangle信息
        /// </summary>
        private void UpdateTabMainDisplayRectangleByTabItemsDisplayRectangle()
        {
            int scale_tabbar_margin_top = (int)Math.Ceiling(this.TabBar.Padding.Top * this.ScaleDpi);
            int scale_tabbar_margin_bottom = (int)Math.Ceiling(this.TabBar.Padding.Bottom * this.ScaleDpi);

            if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Top)
            {
                this.body_c_rect = new Rectangle(
                    this.ClientRectangle.X + this.BodyBorderThickness,
                    this.ClientRectangle.Y + scale_tabbar_margin_top + this.tabbar_items_c_rect.Height + scale_tabbar_margin_bottom + this.BodyBorderThickness,
                    this.ClientRectangle.Width - this.BodyBorderThickness * 2,
                    this.ClientRectangle.Height - scale_tabbar_margin_top - this.tabbar_items_c_rect.Height - scale_tabbar_margin_bottom - this.BodyBorderThickness * 2
                    );
            }
            else if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Bottom)
            {
                this.body_c_rect = new Rectangle(
                    this.ClientRectangle.X + this.BodyBorderThickness,
                    this.ClientRectangle.Y + this.BodyBorderThickness,
                    this.ClientRectangle.Width - this.BodyBorderThickness * 2,
                    this.ClientRectangle.Height - scale_tabbar_margin_top - this.tabbar_items_c_rect.Height - scale_tabbar_margin_bottom - this.BodyBorderThickness * 2
                    );

            }
            else if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Left)
            {
                this.body_c_rect = new Rectangle(
                    this.ClientRectangle.X + scale_tabbar_margin_top + this.tabbar_items_c_rect.Width + scale_tabbar_margin_bottom + this.BodyBorderThickness,
                    this.ClientRectangle.Y + this.BodyBorderThickness,
                    this.ClientRectangle.Width - scale_tabbar_margin_top - this.tabbar_items_c_rect.Width - scale_tabbar_margin_bottom - this.BodyBorderThickness * 2,
                    this.ClientRectangle.Height - this.BodyBorderThickness * 2
                    );
            }
            else if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Right)
            {
                this.body_c_rect = new Rectangle(
                    this.ClientRectangle.X + this.BodyBorderThickness,
                    this.ClientRectangle.Y + this.BodyBorderThickness,
                    this.ClientRectangle.Width - scale_tabbar_margin_top - this.tabbar_items_c_rect.Width - scale_tabbar_margin_bottom - this.BodyBorderThickness * 2,
                    this.ClientRectangle.Height - this.BodyBorderThickness * 2
                    );
            }

            for (int i = 0; i < this.tabPages.Length; i++)
            {
                this.SetTabPageDisplayRectangle(this.tabPages[i]);
            }

        }

        /// <summary>
        /// 设置TabPage的DisplayRectangle
        /// </summary>
        /// <param name="tabPage">要设置的TabPage</param>
        private void SetTabPageDisplayRectangle(TabPagePlus tabPage)
        {
            tabPage.SetBounds(this.body_c_rect.X, this.body_c_rect.Y, this.body_c_rect.Width, this.body_c_rect.Height);
        }

        /// <summary>
        /// 更新TabStop激活的控件
        /// </summary>
        protected void UpdateTabSelection()
        {
            if (this.IsHandleCreated)
            {
                int index = this.SelectedIndex;

                TabPagePlus[] tabPages = this.GetTabPages();
                if (index != -1)
                {
                    if (!Focused)
                    {
                        bool selectNext = tabPages[index].SelectNextControl(null, true, true, false, false);
                        if (selectNext)
                        {
                            if (!this.ContainsFocus)
                            {
                                IContainerControl c = this.GetContainerControl();
                                if (c != null)
                                {
                                    while (c.ActiveControl is ContainerControl)
                                    {
                                        c = (IContainerControl)c.ActiveControl;
                                    }
                                    if (c.ActiveControl != null)
                                    {
                                        c.ActiveControl.Focus();
                                    }
                                }
                            }
                        }
                        else
                        {
                            IContainerControl c = this.GetContainerControl();
                            if (c != null && !DesignMode)
                            {
                                if (c is ContainerControl)
                                {
                                    ((ContainerControl)c).ActiveControl = this;
                                }
                                else
                                {
                                    c.ActiveControl = this;
                                }
                            }
                        }
                    }
                }

            }
        }


        /// <summary>
        /// 绘制选项卡栏背景
        /// </summary>
        /// <param name="g"></param>
        private void DrawTabBarBackground(Graphics g)
        {
            if ((Events[EventTabBarDrawBackground] as TabBarDrawBackgroundEventHandler) == null)
                return;

            Region tabbar_clipbounds_p_region = new Region(this.tabbar_p_rect);
            g.Clip = tabbar_clipbounds_p_region;
            this.OnTabBarDrawBackground(new TabControlPlusTabBarDrawBackgroundEventArgs(this.ScaleDpi, g, this.tabbar_p_rect, this.tabbar_c_rect, this.tabbar_p_rect));
            tabbar_clipbounds_p_region.Dispose();
        }

        /// <summary>
        /// 绘制全局按钮
        /// </summary>
        /// <param name="g"></param>
        private void DrawGlobalButttons(Graphics g)
        {

            if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Top || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Bottom)
            {
                for (int i = this.TabBar.GlobalButttons.Count - 1; i > -1; i--)
                {
                    TabControlPlusGlobalButtton btn = this.TabBar.GlobalButttons[i];
                    if (btn.Visible)
                    {
                        bool btn_image_istmp = false;
                        Image btn_image = null;
                        this.GetGlobalButttonImage(btn, ref btn_image, ref btn_image_istmp);

                        g.DrawImage(btn_image, btn.C_Rect, new RectangleF(0, 0, btn_image.Width, btn_image.Height), GraphicsUnit.Pixel);

                        if (btn_image_istmp)
                        {
                            btn_image.Dispose();
                        }
                    }
                }
            }
            else if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Left || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Right)
            {
                if (this.TabBar.TabItem.VerticalLayout)
                {
                    for (int i = this.TabBar.GlobalButttons.Count - 1; i > -1; i--)
                    {
                        TabControlPlusGlobalButtton btn = this.TabBar.GlobalButttons[i];
                        if (btn.Visible)
                        {
                            bool btn_image_istmp = false;
                            Image btn_image = null;
                            this.GetGlobalButttonImage(btn, ref btn_image, ref btn_image_istmp);

                            btn_image.RotateFlip(RotateFlipType.Rotate90FlipNone);
                            g.DrawImage(btn_image, btn.C_Rect, new RectangleF(0, 0, btn_image.Width, btn_image.Height), GraphicsUnit.Pixel);
                            btn_image.RotateFlip(RotateFlipType.Rotate270FlipNone);

                            if (btn_image_istmp)
                            {
                                btn_image.Dispose();
                            }
                        }
                    }
                }
                else
                {
                    for (int i = this.TabBar.GlobalButttons.Count - 1; i > -1; i--)
                    {
                        TabControlPlusGlobalButtton btn = this.TabBar.GlobalButttons[i];
                        if (btn.Visible)
                        {
                            bool btn_image_istmp = false;
                            Image btn_image = null;
                            this.GetGlobalButttonImage(btn, ref btn_image, ref btn_image_istmp);

                            g.DrawImage(btn_image, btn.C_Rect, new RectangleF(0, 0, btn_image.Width, btn_image.Height), GraphicsUnit.Pixel);

                            if (btn_image_istmp)
                            {
                                btn_image.Dispose();
                            }
                        }
                    }
                }
            }

        }

        /// <summary>
        /// 绘制导航栏
        /// </summary>
        /// <param name="g"></param>
        private void DrawNavigationBar(Graphics g)
        {
            if (!this.TabBar.NavigationBar.Visible || !this.tabbar_navigationbar_visualstatus)
                return;

            Pen navigation_prev_border_pen = new Pen(this.TabBar.NavigationBar.PrevButton.IsMouseEnter ? this.StyleAppearance.TabBar.NavigationButton.Enter.BorderColor : this.StyleAppearance.TabBar.NavigationButton.Normal.BorderColor);
            SolidBrush navigation_prev_back_sb = new SolidBrush(this.TabBar.NavigationBar.PrevButton.IsMouseEnter ? this.StyleAppearance.TabBar.NavigationButton.Enter.BackColor : this.StyleAppearance.TabBar.NavigationButton.Normal.BackColor);
            Pen navigation_next_border_pen = new Pen(this.TabBar.NavigationBar.NextButton.IsMouseEnter ? this.StyleAppearance.TabBar.NavigationButton.Enter.BorderColor : this.StyleAppearance.TabBar.NavigationButton.Normal.BorderColor);
            SolidBrush navigation_next_back_sb = new SolidBrush(this.TabBar.NavigationBar.NextButton.IsMouseEnter ? this.StyleAppearance.TabBar.NavigationButton.Enter.BackColor : this.StyleAppearance.TabBar.NavigationButton.Normal.BackColor);

            PointF[] prev_point = new PointF[3];
            PointF[] next_point = new PointF[3];
            if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Top || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Bottom)
            {
                prev_point[0] = new PointF(this.TabBar.NavigationBar.PrevButton.C_Rect.X, this.TabBar.NavigationBar.PrevButton.C_Rect.Y + this.TabBar.NavigationBar.PrevButton.C_Rect.Height / 2);
                prev_point[1] = new PointF(this.TabBar.NavigationBar.PrevButton.C_Rect.Right, this.TabBar.NavigationBar.PrevButton.C_Rect.Bottom);
                prev_point[2] = new PointF(this.TabBar.NavigationBar.PrevButton.C_Rect.Right, this.TabBar.NavigationBar.PrevButton.C_Rect.Y);

                next_point[0] = new PointF(this.TabBar.NavigationBar.NextButton.C_Rect.Right, this.TabBar.NavigationBar.NextButton.C_Rect.Y + this.TabBar.NavigationBar.NextButton.C_Rect.Height / 2);
                next_point[1] = new PointF(this.TabBar.NavigationBar.NextButton.C_Rect.X, this.TabBar.NavigationBar.NextButton.C_Rect.Bottom);
                next_point[2] = new PointF(this.TabBar.NavigationBar.NextButton.C_Rect.X, this.TabBar.NavigationBar.NextButton.C_Rect.Y);
            }
            else if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Left || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Right)
            {
                if (this.TabBar.TabItem.VerticalLayout)
                {
                    prev_point[0] = new PointF(this.TabBar.NavigationBar.PrevButton.C_Rect.X + this.TabBar.NavigationBar.PrevButton.C_Rect.Width / 2, this.TabBar.NavigationBar.PrevButton.C_Rect.Y);
                    prev_point[1] = new PointF(this.TabBar.NavigationBar.PrevButton.C_Rect.X, this.TabBar.NavigationBar.PrevButton.C_Rect.Bottom);
                    prev_point[2] = new PointF(this.TabBar.NavigationBar.PrevButton.C_Rect.Right, this.TabBar.NavigationBar.PrevButton.C_Rect.Bottom);

                    next_point[0] = new PointF(this.TabBar.NavigationBar.NextButton.C_Rect.X + this.TabBar.NavigationBar.NextButton.C_Rect.Width / 2, this.TabBar.NavigationBar.NextButton.C_Rect.Bottom);
                    next_point[1] = new PointF(this.TabBar.NavigationBar.NextButton.C_Rect.X, this.TabBar.NavigationBar.NextButton.C_Rect.Y);
                    next_point[2] = new PointF(this.TabBar.NavigationBar.NextButton.C_Rect.Right, this.TabBar.NavigationBar.NextButton.C_Rect.Y);
                }
                else
                {
                    prev_point[0] = new PointF(this.TabBar.NavigationBar.PrevButton.C_Rect.X, this.TabBar.NavigationBar.PrevButton.C_Rect.Y + this.TabBar.NavigationBar.PrevButton.C_Rect.Height / 2);
                    prev_point[1] = new PointF(this.TabBar.NavigationBar.PrevButton.C_Rect.Right, this.TabBar.NavigationBar.PrevButton.C_Rect.Bottom);
                    prev_point[2] = new PointF(this.TabBar.NavigationBar.PrevButton.C_Rect.Right, this.TabBar.NavigationBar.PrevButton.C_Rect.Y);

                    next_point[0] = new PointF(this.TabBar.NavigationBar.NextButton.C_Rect.Right, this.TabBar.NavigationBar.NextButton.C_Rect.Y + this.TabBar.NavigationBar.NextButton.C_Rect.Height / 2);
                    next_point[1] = new PointF(this.TabBar.NavigationBar.NextButton.C_Rect.X, this.TabBar.NavigationBar.NextButton.C_Rect.Bottom);
                    next_point[2] = new PointF(this.TabBar.NavigationBar.NextButton.C_Rect.X, this.TabBar.NavigationBar.NextButton.C_Rect.Y);
                }
            }

            SmoothingMode source_sm = g.SmoothingMode;
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.FillPolygon(navigation_prev_back_sb, prev_point);
            g.DrawPolygon(navigation_prev_border_pen, prev_point);
            g.FillPolygon(navigation_next_back_sb, next_point);
            g.DrawPolygon(navigation_next_border_pen, next_point);
            g.SmoothingMode = source_sm;

            navigation_prev_border_pen.Dispose();
            navigation_prev_back_sb.Dispose();
            navigation_next_border_pen.Dispose();
            navigation_next_back_sb.Dispose();
        }

        /// <summary>
        /// 绘制选项
        /// </summary>
        /// <param name="g"></param>
        private void DrawTabItem(Graphics g)
        {
            if (this.TabCount < 1)
                return;

            NativeMethods.TEXTMETRIC font_metrics = ControlHelper.GetFontMetrics(this.Handle, this.Font);

            //存放选项通用笔刷
            SolidBrush tabitem_back_normal_commom_sb = null;
            SolidBrush tabitem_back_enter_commom_sb = null;
            SolidBrush tabitem_back_selected_commom_sb = null;
            SolidBrush tabitem_back_disable_commom_sb = null;

            SolidBrush tabitem_text_normal_commom_sb = null;
            SolidBrush tabitem_text_enter_commom_sb = null;
            SolidBrush tabitem_text_selected_commom_sb = null;
            SolidBrush tabitem_text_disable_commom_sb = null;

            StringFormat text_sf = new StringFormat() { Alignment = this.TabBar.TabItem.TextAlignment };

            //存放选项关闭按钮通用笔刷
            SolidBrush tabitem_closebutton_back_normal_commom_sb = null;
            SolidBrush tabitem_closebutton_back_enter_commom_sb = null;
            SolidBrush tabitem_closebutton_back_disable_commom_sb = null;
            Pen tabitem_closebutton_fore_normal_commom_pen = null;
            Pen tabitem_closebutton_fore_enter_commom_pen = null;
            Pen tabitem_closebutton_fore_disable_commom_pen = null;


            for (int i = 0; i < this.TabCount; i++)
            {
                if (!this.GetTabItemVisualStatus(this.TabPages[i]))
                    continue;

                TabPagePlus tab_page = this.TabPages[i];

                SolidBrush tabitem_back_sb = null;
                SolidBrush tabitem_text_sb = null;
                this.GetProperty_ItemSolidBrush(tab_page, ref tabitem_back_normal_commom_sb, ref tabitem_back_enter_commom_sb, ref tabitem_back_selected_commom_sb, ref tabitem_back_disable_commom_sb, ref tabitem_back_sb, ref tabitem_text_normal_commom_sb, ref tabitem_text_enter_commom_sb, ref tabitem_text_selected_commom_sb, ref tabitem_text_disable_commom_sb, ref tabitem_text_sb);

                RectangleF item_clip_bounds_p = new RectangleF(tab_page.P_Rect.X, tab_page.P_Rect.Y, tab_page.P_Rect.Width, tab_page.P_Rect.Height);
                item_clip_bounds_p.Intersect(this.tabbar_items_c_rect);

                RectangleF item_clip_bounds_c = new RectangleF(tab_page.C_Rect.X, tab_page.C_Rect.Y, tab_page.C_Rect.Width, tab_page.C_Rect.Height);
                item_clip_bounds_c.Intersect(this.tabbar_items_c_rect);

                Region tabitem_clipbounds_p_region = new Region(tab_page.P_GP);
                tabitem_clipbounds_p_region.Intersect(this.tabbar_items_c_rect);
                g.Clip = tabitem_clipbounds_p_region;

                // 绘制背景
                this.DrawTabItemBackground(g, tab_page, item_clip_bounds_p, tabitem_back_sb);

                Region tabitem_clipbounds_c_region = tabitem_clipbounds_p_region.Clone();
                tabitem_clipbounds_c_region.Intersect(tab_page.C_Rect);
                g.Clip = tabitem_clipbounds_c_region;

                // 绘制选项图标
                this.DrawTabItemIco(g, tab_page, item_clip_bounds_c);

                // 绘制选项文本
                this.DrawTabItemText(g, tab_page, item_clip_bounds_c, tabitem_text_sb, text_sf);

                // 绘制选项自定义按钮
                this.DrawTabItemCustomButtons(g, tab_page, item_clip_bounds_c);

                // 绘制选项关闭按钮
                this.DrawTabItemCloseButton(g, tab_page, item_clip_bounds_c, tabitem_closebutton_back_normal_commom_sb, tabitem_closebutton_back_enter_commom_sb, tabitem_closebutton_back_disable_commom_sb, tabitem_closebutton_fore_normal_commom_pen, tabitem_closebutton_fore_enter_commom_pen, tabitem_closebutton_fore_disable_commom_pen);

                tabitem_clipbounds_c_region.Dispose();
                tabitem_clipbounds_p_region.Dispose();
            }


            if (tabitem_back_normal_commom_sb != null)
                tabitem_back_normal_commom_sb.Dispose();
            if (tabitem_back_enter_commom_sb != null)
                tabitem_back_enter_commom_sb.Dispose();
            if (tabitem_back_selected_commom_sb != null)
                tabitem_back_selected_commom_sb.Dispose();
            if (tabitem_back_disable_commom_sb != null)
                tabitem_back_disable_commom_sb.Dispose();
            if (tabitem_text_normal_commom_sb != null)
                tabitem_text_normal_commom_sb.Dispose();
            if (tabitem_text_enter_commom_sb != null)
                tabitem_text_enter_commom_sb.Dispose();
            if (tabitem_text_selected_commom_sb != null)
                tabitem_text_selected_commom_sb.Dispose();
            if (tabitem_text_disable_commom_sb != null)
                tabitem_text_disable_commom_sb.Dispose();

            if (text_sf != null)
                text_sf.Dispose();

            if (tabitem_closebutton_back_normal_commom_sb != null)
                tabitem_closebutton_back_normal_commom_sb.Dispose();
            if (tabitem_closebutton_back_enter_commom_sb != null)
                tabitem_closebutton_back_enter_commom_sb.Dispose();
            if (tabitem_closebutton_back_disable_commom_sb != null)
                tabitem_closebutton_back_disable_commom_sb.Dispose();
            if (tabitem_closebutton_fore_normal_commom_pen != null)
                tabitem_closebutton_fore_normal_commom_pen.Dispose();
            if (tabitem_closebutton_fore_enter_commom_pen != null)
                tabitem_closebutton_fore_enter_commom_pen.Dispose();
            if (tabitem_closebutton_fore_disable_commom_pen != null)
                tabitem_closebutton_fore_disable_commom_pen.Dispose();

        }

        /// <summary>
        /// 绘制选项背景
        /// </summary>
        /// <param name="g"></param>
        /// <param name="tab_page">选项</param>
        /// <param name="item_clip_bounds_p">选项剪切区域（包含:内边距、内容）</param>
        /// <param name="tabitem_back_sb">背景画笔</param>
        private void DrawTabItemBackground(Graphics g, TabPagePlus tab_page, RectangleF item_clip_bounds_p, SolidBrush tabitem_back_sb)
        {
            SmoothingMode item_background_source_sm = g.SmoothingMode;
            if (this.TabBar.TabItem.RoundQuality)
            {
                g.SmoothingMode = SmoothingMode.AntiAlias;
            }

            TabControlPlusTabItemDrawBackgroundBeforeEventArgs tabitem_background_before_arg = new TabControlPlusTabItemDrawBackgroundBeforeEventArgs(tab_page, this.ScaleDpi, g, this.tabbar_p_rect, this.tabbar_c_rect, this.tabbar_items_c_rect, tab_page.M_Rect, tab_page.P_Rect, tab_page.C_Rect, item_clip_bounds_p, false);
            this.OnTabItemDrawBackgroundBefore(tabitem_background_before_arg);
            if (tabitem_background_before_arg.Cancel == false)
            {
                g.FillPath(tabitem_back_sb, tab_page.P_GP);
                this.OnTabItemDrawBackgroundAfter(new TabControlPlusTabItemDrawBackgroundAfterEventArgs(tab_page, this.ScaleDpi, g, this.tabbar_p_rect, this.tabbar_c_rect, this.tabbar_items_c_rect, tab_page.M_Rect, tab_page.P_Rect, tab_page.C_Rect, item_clip_bounds_p));
            }

            g.SmoothingMode = item_background_source_sm;

        }

        /// <summary>
        /// 绘制选项图标
        /// </summary>
        /// <param name="g"></param>
        /// <param name="tab_page">选项</param>
        /// <param name="item_clipbounds_c">选项剪切区域（包含:内容）</param>
        private void DrawTabItemIco(Graphics g, TabPagePlus tab_page, RectangleF item_clipbounds_c)
        {
            if (!this.GetProperty_ItemIcoVisible(tab_page))
                return;

            RectangleF tabitem_ico_clipbounds_c = new RectangleF(tab_page.Icon_C_Rect.X, tab_page.Icon_C_Rect.Y, tab_page.Icon_C_Rect.Width, tab_page.Icon_C_Rect.Height);
            tabitem_ico_clipbounds_c.Intersect(tab_page.C_Rect);
            tabitem_ico_clipbounds_c.Intersect(this.tabbar_items_c_rect);

            Image tabitem_ico_image = null;
            bool tabitem_ico_image_is_tmp = false;
            this.GetProperty_ItemIcoImage(tab_page, ref tabitem_ico_image, ref tabitem_ico_image_is_tmp);

            if ((this.TabBar.Alignment == TabControlPlusTabBarAlignment.Left || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Right) && this.TabBar.TabItem.VerticalLayout)
            {
                tabitem_ico_image.RotateFlip(RotateFlipType.Rotate90FlipNone);
                g.DrawImage(tabitem_ico_image, tab_page.Icon_C_Rect, new Rectangle(0, 0, tabitem_ico_image.Width, tabitem_ico_image.Height), GraphicsUnit.Pixel);
                tabitem_ico_image.RotateFlip(RotateFlipType.Rotate270FlipNone);
            }
            else
            {
                g.DrawImage(tabitem_ico_image, tab_page.Icon_C_Rect, new Rectangle(0, 0, tabitem_ico_image.Width, tabitem_ico_image.Height), GraphicsUnit.Pixel);
            }

            tab_page.OnTabItemIconDrawAfter(new TabControlPlusTabItemIconDrawAfterEventArgs(tab_page, this.ScaleDpi, g, this.tabbar_p_rect, this.tabbar_c_rect, item_clipbounds_c, tab_page.Icon_M_Rect, tab_page.Icon_C_Rect, tabitem_ico_clipbounds_c));

            if (tabitem_ico_image_is_tmp && tabitem_ico_image != null)
            {
                tabitem_ico_image.Dispose();
                tabitem_ico_image = null;
            }
        }

        /// <summary>
        /// 绘制选项文本
        /// </summary>
        /// <param name="g"></param>
        /// <param name="tab_page">选项</param>
        /// <param name="item_clipbounds_c">选项剪切区域（包含:内容）</param>
        /// <param name="tabitem_text_sb">文本画笔</param>
        /// <param name="text_sf">文本布局样式</param>
        private void DrawTabItemText(Graphics g, TabPagePlus tab_page, RectangleF item_clipbounds_c, SolidBrush tabitem_text_sb, StringFormat text_sf)
        {
            if ((this.TabBar.Alignment == TabControlPlusTabBarAlignment.Left || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Right) && this.TabBar.TabItem.VerticalLayout)
            {
                //纵向文本
                if (tab_page.TabItem.VerticalLayout == false)
                {
                    if (tab_page.Text_C_Rect.Width > 0)
                    {
                        text_sf.Trimming = tab_page.TabItem.TextEllipsisCharacter ? StringTrimming.EllipsisCharacter : StringTrimming.None;
                        g.TranslateTransform(tab_page.Text_C_Rect.Right, tab_page.Text_C_Rect.Y);
                        g.RotateTransform(90);
                        g.DrawString(tab_page.Text, this.Font, tabitem_text_sb, new RectangleF(0, 0, tab_page.Text_C_Rect.Height, tab_page.Text_C_Rect.Width), text_sf);
                        g.ResetTransform();
                    }
                }
                //垂直文本
                else
                {
                    if (tab_page.Text_C_Rect.Height > 0)
                    {
                        text_sf.Trimming = StringTrimming.None;
                        g.DrawString(tab_page.TextVerticalLayoutTmp, this.Font, tabitem_text_sb, tab_page.Text_C_Rect);
                    }
                }
            }
            //横向文本
            else
            {
                if (tab_page.Text_C_Rect.Width > 0)
                {
                    text_sf.Trimming = tab_page.TabItem.TextEllipsisCharacter ? StringTrimming.EllipsisCharacter : StringTrimming.None;
                    g.DrawString(tab_page.Text, this.Font, tabitem_text_sb, tab_page.Text_C_Rect, text_sf);
                }
            }

        }

        /// <summary>
        /// 绘制选项自定义按钮
        /// </summary>
        /// <param name="g"></param>
        /// <param name="tab_page">选项</param>
        /// <param name="item_clipbounds_c">选项剪切区域（包含:内容）</param>
        private void DrawTabItemCustomButtons(Graphics g, TabPagePlus tab_page, RectangleF item_clipbounds_c)
        {
            for (int k = 0; k < tab_page.TabItem.CustomButtons.Count; k++)
            {
                TabControlPlusTabItemCustomButton custombutton = tab_page.TabItem.CustomButtons[k];
                if (custombutton.Visible)
                {
                    RectangleF tabitem_custombutton_clipbounds_c = new RectangleF(custombutton.C_Rect.X, custombutton.C_Rect.Y, custombutton.C_Rect.Width, custombutton.C_Rect.Height);
                    tabitem_custombutton_clipbounds_c.Intersect(tab_page.C_Rect);
                    tabitem_custombutton_clipbounds_c.Intersect(this.tabbar_items_c_rect);

                    Image tabitem_custombutton_image = null;
                    bool tabitem_custombutton_image_istmp = false;
                    this.GetProperty_ItemCustomButttonImage(tab_page, custombutton, ref tabitem_custombutton_image, ref tabitem_custombutton_image_istmp);

                    if ((this.TabBar.Alignment == TabControlPlusTabBarAlignment.Left || this.TabBar.Alignment == TabControlPlusTabBarAlignment.Right) && this.TabBar.TabItem.VerticalLayout)
                    {
                        tabitem_custombutton_image.RotateFlip(RotateFlipType.Rotate90FlipNone);
                        g.DrawImage(tabitem_custombutton_image, custombutton.C_Rect, new Rectangle(0, 0, tabitem_custombutton_image.Width, tabitem_custombutton_image.Height), GraphicsUnit.Pixel);
                        tabitem_custombutton_image.RotateFlip(RotateFlipType.Rotate270FlipNone);
                    }
                    else
                    {
                        g.DrawImage(tabitem_custombutton_image, custombutton.C_Rect, new Rectangle(0, 0, tabitem_custombutton_image.Width, tabitem_custombutton_image.Height), GraphicsUnit.Pixel);
                    }

                    custombutton.OnTabItemCusomButtonDrawAfter(new TabControlPlusTabItemCustomButtonDrawAfterEventArgs(tab_page, custombutton, this.ScaleDpi, g, this.tabbar_p_rect, this.tabbar_c_rect, item_clipbounds_c, custombutton.M_Rect, custombutton.C_Rect, tabitem_custombutton_clipbounds_c));

                    if (tabitem_custombutton_image_istmp && tabitem_custombutton_image != null)
                    {
                        tabitem_custombutton_image.Dispose();
                        tabitem_custombutton_image = null;
                    }
                }
            }
        }

        /// <summary>
        /// 绘制选项关闭按钮
        /// </summary>
        /// <param name="g"></param>
        /// <param name="tab_page">选项</param>
        /// <param name="item_clipbounds_c">选项剪切区域（包含:内容）</param>
        /// <param name="tabitem_closebutton_back_normal_commom_sb">关闭按钮背景色通用画笔（正常）</param>
        /// <param name="tabitem_closebutton_back_enter_commom_sb">关闭按钮背景色通用画笔（鼠标进入）</param>
        /// <param name="tabitem_closebutton_back_disable_commom_sb">关闭按钮背景色通用画笔（禁用）</param>
        /// <param name="tabitem_closebutton_fore_normal_commom_pen">关闭按钮前景色通用画笔（正常）</param>
        /// <param name="tabitem_closebutton_fore_enter_commom_pen">关闭按钮前景色通用画笔（鼠标进入）</param>
        /// <param name="tabitem_closebutton_fore_disable_commom_pen">关闭按钮前景色通用画笔（禁用）</param>
        private void DrawTabItemCloseButton(Graphics g, TabPagePlus tab_page, RectangleF item_clipbounds_c, SolidBrush tabitem_closebutton_back_normal_commom_sb, SolidBrush tabitem_closebutton_back_enter_commom_sb, SolidBrush tabitem_closebutton_back_disable_commom_sb, Pen tabitem_closebutton_fore_normal_commom_pen, Pen tabitem_closebutton_fore_enter_commom_pen, Pen tabitem_closebutton_fore_disable_commom_pen)
        {
            if (!this.GetProperty_ItemColseVisible(tab_page))
                return;

            TabPagePlus.TabItemObject.CloseButtonObject closebutton = tab_page.TabItem.CloseButton;

            RectangleF tabitem_closebutton_clipbounds_c = new RectangleF(closebutton.C_Rect.X, closebutton.C_Rect.Y, closebutton.C_Rect.Width, closebutton.C_Rect.Height);
            tabitem_closebutton_clipbounds_c.Intersect(tab_page.C_Rect);
            tabitem_closebutton_clipbounds_c.Intersect(this.tabbar_items_c_rect);

            Region tabitem_closebutton_region_c_before = g.Clip;
            Region tabitem_closebutton_region_c = tabitem_closebutton_region_c_before.Clone();
            tabitem_closebutton_region_c.Intersect(tabitem_closebutton_clipbounds_c);
            g.Clip = tabitem_closebutton_region_c;

            SolidBrush closebutton_back_sb = null;
            Pen closebutton_fore_pen = null;
            this.GetTabItemClosePen(tab_page, ref tabitem_closebutton_back_normal_commom_sb, ref tabitem_closebutton_back_enter_commom_sb, ref tabitem_closebutton_back_disable_commom_sb, ref closebutton_back_sb, ref tabitem_closebutton_fore_normal_commom_pen, ref tabitem_closebutton_fore_enter_commom_pen, ref tabitem_closebutton_fore_disable_commom_pen, ref closebutton_fore_pen);

            TabControlPlusTabItemCloseButtonDrawBeforeEventArgs tabitem_closebutton_before_arg = new TabControlPlusTabItemCloseButtonDrawBeforeEventArgs(tab_page, this.ScaleDpi, g, closebutton_back_sb, closebutton_fore_pen, this.tabbar_p_rect, this.tabbar_c_rect, item_clipbounds_c, closebutton.M_Rect, closebutton.C_Rect, tabitem_closebutton_clipbounds_c, false);
            tab_page.OnTabItemCloseButtonDrawBefore(tabitem_closebutton_before_arg);
            if (tabitem_closebutton_before_arg.Cancel == false)
            {
                g.FillRectangle(closebutton_back_sb, closebutton.C_Rect);

                SmoothingMode source_sm = g.SmoothingMode;
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.DrawLine(closebutton_fore_pen, new PointF(closebutton.C_Rect.X + closebutton_fore_pen.Width, closebutton.C_Rect.Y + closebutton_fore_pen.Width), new PointF(closebutton.C_Rect.Right - closebutton_fore_pen.Width, closebutton.C_Rect.Bottom - closebutton_fore_pen.Width));
                g.DrawLine(closebutton_fore_pen, new PointF(closebutton.C_Rect.Right - closebutton_fore_pen.Width, closebutton.C_Rect.Y + closebutton_fore_pen.Width), new PointF(closebutton.C_Rect.Left + closebutton_fore_pen.Width, closebutton.C_Rect.Bottom - closebutton_fore_pen.Width));
                g.SmoothingMode = source_sm;
            }

            g.Clip = tabitem_closebutton_region_c_before;
            tabitem_closebutton_region_c.Dispose();

        }

        /// <summary>
        /// 绘制主体区域
        /// </summary>
        /// <param name="g"></param>
        private void DrawBody(Graphics g)
        {
            g.ResetClip();

            SolidBrush body_back_sb = new SolidBrush(this.StyleAppearance.Body.BackColor);
            g.FillRectangle(body_back_sb, this.body_c_rect);
            body_back_sb.Dispose();

            if (this.BodyBorderThickness > 0)
            {
                Pen body_border_pen = new Pen(this.StyleAppearance.Body.BorderColor, this.BodyBorderThickness) { Alignment = PenAlignment.Inset };
                g.DrawRectangle(body_border_pen, new Rectangle(this.body_c_rect.X - this.BodyBorderThickness, this.body_c_rect.Y - this.BodyBorderThickness, this.body_c_rect.Width - (this.BodyBorderThickness == 1 ? 1 : 0) + this.BodyBorderThickness * 2, this.body_c_rect.Height - (this.BodyBorderThickness == 1 ? 1 : 0) + this.BodyBorderThickness * 2));
                body_border_pen.Dispose();
            }
        }

        /// <summary>
        /// 获取视觉上全局按钮是否显示
        /// </summary>
        /// <returns></returns>
        private bool GetGlobalButttonVisualstatus()
        {
            for (int i = 0; i < this.TabBar.GlobalButttons.Count; i++)
            {
                if (this.TabBar.GlobalButttons[i].Visible)
                {
                    return true;
                }
            }

            return false;
        }

        /// <summary>
        /// 获取全局按钮的图片
        /// </summary>
        /// <param name="btn">全局按钮</param>
        /// <param name="btn_image">返回按钮图片</param>
        /// <param name="btn_image_istmp">返回按钮图片是否为临时（如果是,用完需要手动释放）</param>
        private void GetGlobalButttonImage(TabControlPlusGlobalButtton btn, ref Image btn_image, ref bool btn_image_istmp)
        {
            btn_image_istmp = false;
            if (this.mouseenterobjectchildren == btn)
            {
                btn_image = btn.ImageEnter;
            }
            else
            {
                btn_image = btn.ImageNormal;
            }
            if (btn_image == null)
            {
                btn_image = HML.TabControlPlusResources.TabControlPlus_item_default_button_ico;
            }

        }



        /// <summary>
        /// 获取指定TabPage笔刷
        /// </summary>
        /// <param name="tabPage">指定TabPage</param>
        /// <param name="tabitem_back_normal_commom_sb"></param>
        /// <param name="tabitem_back_enter_commom_sb"></param>
        /// <param name="tabitem_back_selected_commom_sb"></param>
        /// <param name="tabitem_back_disable_commom_sb"></param>
        /// <param name="tabitem_back_sb"></param>
        /// <param name="tabitem_text_normal_commom_sb"></param>
        /// <param name="tabitem_text_enter_commom_sb"></param>
        /// <param name="tabitem_text_selected_commom_sb"></param>
        /// <param name="tabitem_text_disable_commom_sb"></param>
        /// <param name="tabitem_text_sb"></param>
        /// <returns></returns>
        private void GetProperty_ItemSolidBrush(TabPagePlus tabPage,
            ref SolidBrush tabitem_back_normal_commom_sb,
            ref SolidBrush tabitem_back_enter_commom_sb,
            ref SolidBrush tabitem_back_selected_commom_sb,
            ref SolidBrush tabitem_back_disable_commom_sb,
            ref SolidBrush tabitem_back_sb,
            ref SolidBrush tabitem_text_normal_commom_sb,
            ref SolidBrush tabitem_text_enter_commom_sb,
            ref SolidBrush tabitem_text_selected_commom_sb,
            ref SolidBrush tabitem_text_disable_commom_sb,
            ref SolidBrush tabitem_text_sb
            )
        {
            if (!tabPage.TabItem.Enabled)
            {
                if (tabitem_back_disable_commom_sb == null)
                {
                    tabitem_back_disable_commom_sb = new SolidBrush(this.StyleAppearance.TabBar.TabItem.Disabled.BackColor);
                }
                tabitem_back_sb = tabitem_back_disable_commom_sb;

                if (tabitem_text_disable_commom_sb == null)
                {
                    tabitem_text_disable_commom_sb = new SolidBrush(this.StyleAppearance.TabBar.TabItem.Disabled.TextColor);
                }
                tabitem_text_sb = tabitem_text_disable_commom_sb;
            }
            else if (this.JudgeTabPageIsSelect(tabPage))
            {
                if (tabitem_back_selected_commom_sb == null)
                {
                    tabitem_back_selected_commom_sb = new SolidBrush(this.StyleAppearance.TabBar.TabItem.Selected.BackColor);
                }
                tabitem_back_sb = tabitem_back_selected_commom_sb;

                if (tabitem_text_selected_commom_sb == null)
                {
                    tabitem_text_selected_commom_sb = new SolidBrush(this.StyleAppearance.TabBar.TabItem.Selected.TextColor);
                }
                tabitem_text_sb = tabitem_text_selected_commom_sb;

            }
            else if (tabPage.IsMouseEnter)
            {
                if (tabitem_back_enter_commom_sb == null)
                {
                    tabitem_back_enter_commom_sb = new SolidBrush(this.StyleAppearance.TabBar.TabItem.Enter.BackColor);
                }
                tabitem_back_sb = tabitem_back_enter_commom_sb;

                if (tabitem_text_enter_commom_sb == null)
                {
                    tabitem_text_enter_commom_sb = new SolidBrush(this.StyleAppearance.TabBar.TabItem.Enter.TextColor);
                }
                tabitem_text_sb = tabitem_text_enter_commom_sb;

            }
            else
            {
                if (tabitem_back_normal_commom_sb == null)
                {
                    tabitem_back_normal_commom_sb = new SolidBrush(this.StyleAppearance.TabBar.TabItem.Normal.BackColor);
                }
                tabitem_back_sb = tabitem_back_normal_commom_sb;

                if (tabitem_text_normal_commom_sb == null)
                {
                    tabitem_text_normal_commom_sb = new SolidBrush(this.StyleAppearance.TabBar.TabItem.Normal.TextColor);
                }
                tabitem_text_sb = tabitem_text_normal_commom_sb;
            }
        }

        /// <summary>
        /// 获取Tab选项关闭按钮画笔
        /// </summary>
        /// <param name="tabPage">Tab选项</param>
        /// <param name="close_back_normal_commom_sb">通用背景色画笔(正常)</param>
        /// <param name="close_back_enter_commom_sb">通用背景色画笔(鼠标进入)</param>
        /// <param name="close_back_disable_commom_sb">通用背景色画笔(禁用)</param>
        /// <param name="close_back_sb">专用背景色画笔</param>
        /// <param name="close_fore_normal_commom_pen">通用前景色画笔(正常)</param>
        /// <param name="close_fore_enter_commom_pen">通用前景色画笔(鼠标进入)</param>
        /// <param name="close_fore_disable_commom_pen">通用前景色画笔(禁用)</param>
        /// <param name="close_fore_pen">专用前景色画笔</param>
        private void GetTabItemClosePen(TabPagePlus tabPage,
            ref SolidBrush close_back_normal_commom_sb,
            ref SolidBrush close_back_enter_commom_sb,
            ref SolidBrush close_back_disable_commom_sb,
            ref SolidBrush close_back_sb,
            ref Pen close_fore_normal_commom_pen,
            ref Pen close_fore_enter_commom_pen,
            ref Pen close_fore_disable_commom_pen,
            ref Pen close_fore_pen
            )
        {
            if (!tabPage.TabItem.Enabled || !tabPage.TabItem.CloseButton.Enabled)
            {
                if (close_back_disable_commom_sb == null)
                {
                    close_back_disable_commom_sb = new SolidBrush(this.StyleAppearance.TabBar.TabItem.CloseButton.Disabled.BackColor);
                }
                close_back_sb = close_back_disable_commom_sb;

                if (close_fore_disable_commom_pen == null)
                {
                    close_fore_disable_commom_pen = new Pen(this.StyleAppearance.TabBar.TabItem.CloseButton.Disabled.ForeColor, 2) { StartCap = LineCap.Round, EndCap = LineCap.Round };
                }
                close_fore_pen = close_fore_disable_commom_pen;

            }
            else if (this.mouseenterobjectchildren == tabPage.TabItem.CloseButton)
            {
                if (close_back_enter_commom_sb == null)
                {
                    close_back_enter_commom_sb = new SolidBrush(this.StyleAppearance.TabBar.TabItem.CloseButton.Enter.BackColor);
                }
                close_back_sb = close_back_enter_commom_sb;

                if (close_fore_enter_commom_pen == null)
                {
                    close_fore_enter_commom_pen = new Pen(this.StyleAppearance.TabBar.TabItem.CloseButton.Enter.ForeColor, 2) { StartCap = LineCap.Round, EndCap = LineCap.Round };
                }
                close_fore_pen = close_fore_enter_commom_pen;

            }
            else
            {
                if (close_back_normal_commom_sb == null)
                {
                    close_back_normal_commom_sb = new SolidBrush(this.StyleAppearance.TabBar.TabItem.CloseButton.Normal.BackColor);
                }
                close_back_sb = close_back_normal_commom_sb;

                if (close_fore_normal_commom_pen == null)
                {
                    close_fore_normal_commom_pen = new Pen(this.StyleAppearance.TabBar.TabItem.CloseButton.Normal.ForeColor, 2) { StartCap = LineCap.Round, EndCap = LineCap.Round };
                }
                close_fore_pen = close_fore_normal_commom_pen;

            }
        }

        /// <summary>
        /// 视觉上TabItem是否正在tabtop_items_display_rect区域显示
        /// </summary>
        /// <param name="tabPage">指定TabItem</param>
        private bool GetTabItemVisualStatus(TabPagePlus tabPage)
        {
            if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Top)
            {
                return (tabPage.P_Rect.Right >= this.tabbar_items_c_rect.X && tabPage.P_Rect.X <= this.tabbar_items_c_rect.Right);
            }
            else if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Bottom)
            {
                return (tabPage.P_Rect.Right >= this.tabbar_items_c_rect.X && tabPage.P_Rect.X <= this.tabbar_items_c_rect.Right);
            }
            else if (this.TabBar.Alignment == TabControlPlusTabBarAlignment.Left)
            {
                return (tabPage.P_Rect.Bottom >= this.tabbar_items_c_rect.Y && tabPage.P_Rect.Y <= this.tabbar_items_c_rect.Bottom);
            }
            else
            {
                return (tabPage.P_Rect.Bottom >= this.tabbar_items_c_rect.Y && tabPage.P_Rect.Y <= this.tabbar_items_c_rect.Bottom);
            }
        }

        /// <summary>
        /// 判断指定TabPage是否选中
        /// </summary>
        /// <param name="tabPage">指定TabPage</param>
        /// <returns></returns>
        private bool JudgeTabPageIsSelect(TabPagePlus tabPage)
        {
            if (tabPage == null || this.SelectedIndex < 0 || this.SelectedIndex >= this.TabCount)
                return false;

            return this.TabPages[this.SelectedIndex] == tabPage;
        }

        /// <summary>
        /// 设置指定索引TabPage为激活页
        /// </summary>
        /// <param name="index">要激活的TabPage</param>
        private void SetActiveTabPage(int index)
        {
            if (index < 0 || index >= this.TabCount)
                return;

            for (int i = 0; i < this.TabCount; i++)
            {
                if (this.tabPages[i].Visible != false)
                {
                    this.tabPages[i].Visible = false;
                }
            }

            this.tabPages[index].Visible = true;
        }

        /// <summary>
        /// 隐藏提示信息
        /// </summary>
        private void TipHide()
        {
            if (ttp_owner != null && ttp_owner.Equals(this))
            {
                ttp.Hide(this);
            }
        }

        /// <summary>
        /// 显示提示信息
        /// </summary>
        /// <param name="tipParts">要隐藏的部件</param>
        private void TipShow(object tipParts)
        {
            Type type = tipParts.GetType();
            string text = "";
            Rectangle rect = Rectangle.Empty;
            if (type == typeof(TabControlPlusGlobalButtton))
            {
                TabControlPlusGlobalButtton btn = (TabControlPlusGlobalButtton)tipParts;
                text = btn.TipText;
                rect = new Rectangle((int)btn.C_Rect.X, (int)btn.C_Rect.Y, (int)btn.C_Rect.Width, (int)btn.C_Rect.Height);
            }
            else if (type == typeof(TabControlPlusTabItemCustomButton))
            {
                TabControlPlusTabItemCustomButton btn = (TabControlPlusTabItemCustomButton)tipParts;
                text = btn.TipText;
                rect = new Rectangle((int)btn.C_Rect.X, (int)btn.C_Rect.Y, (int)btn.C_Rect.Width, (int)btn.C_Rect.Height);
            }
            if (!String.IsNullOrEmpty(text))
            {
                if (ttp == null)
                {
                    ttp = new ToolTipPlus() { BorderVisible = false };
                }

                ttp_owner = this;
                ttp.AnchorSpace = (int)(4 * this.ScaleDpi);
                ttp.StyleAppearance.BorderColor = this.StyleAppearance.Tip.BorderColor;
                ttp.StyleAppearance.BackColor = this.StyleAppearance.Tip.BackColor;
                ttp.StyleAppearance.TextColor = this.StyleAppearance.Tip.TextColor;
                ttp.Show(text, this, rect, ToolTipPlusAnchors.TopCenter);
            }

        }

        #endregion

        #region 类

        /// <summary>
        /// 重写TabControlPlus只允许添加TabPagePlus类型的子控件
        /// </summary>
        [ComVisible(false)]
        [Editor(typeof(TabControlPlusControlsCollectionEditor), typeof(UITypeEditor))]
        public class TabControlPlusControlsCollection : Control.ControlCollection
        {
            #region 字段

            private TabControlPlus owner;

            #endregion

            public TabControlPlusControlsCollection(TabControlPlus owner) : base(owner)
            {
                this.owner = owner;
            }

            #region 重写

            public override void Add(Control value)
            {
                if (!(value is TabPagePlus))
                {
                    throw new ArgumentException("添加的类型必须为 TabPagePlus");
                }

                TabPagePlus tabPage = (TabPagePlus)value;
                tabPage.Visible = false;
                base.Add(tabPage);
                owner.AddTabPage(tabPage);
            }

            public override void Remove(Control value)
            {
                base.Remove(value);
                if (!(value is TabPagePlus))
                {
                    return;
                }

                int index = owner.FindTabPage((TabPagePlus)value);
                if (index != -1)
                {
                    owner.RemoveTabPage(index);
                }

            }

            #endregion

        }


        [TypeConverter(typeof(PropertyOrderConverter))]
        public class TabBarObject
        {
            private TabControlPlus owner = null;
            internal TabBarObject(TabControlPlus owner) { this.owner = owner; }

            #region 属性

            private TabControlPlusTabBarAlignment alignment = TabControlPlusTabBarAlignment.Top;
            /// <summary>
            /// 布局对齐方式
            /// </summary>
            [Description("布局对齐方式")]
            [PropertyOrder(-200)]
            [DefaultValue(TabControlPlusTabBarAlignment.Top)]
            public TabControlPlusTabBarAlignment Alignment
            {
                get { return this.alignment; }
                set
                {
                    if (this.alignment == value)
                        return;

                    this.alignment = value;
                    if (this.owner != null)
                    {
                        this.owner.InitializeElement();
                        this.owner.Invalidate();
                    }
                }
            }

            private Padding padding = new Padding(0, 0, 0, 0);
            /// <summary>
            /// 内边距
            /// </summary>
            [Description("内边距")]
            [PropertyOrder(-198)]
            [DefaultValue(typeof(Padding), "0,0,0,0")]
            public Padding Padding
            {
                get { return this.padding; }
                set
                {
                    if (this.padding == value || value.Left < 0 || value.Right < 0 || value.Top < 0 || value.Bottom < 0)
                        return;

                    this.padding = value;
                    if (this.owner != null)
                    {
                        this.owner.InitializeElement();
                        this.owner.Invalidate();
                    }
                }
            }

            private TabItemObject tabItem;
            /// <summary>
            /// 选项
            /// </summary>
            [Description("选项")]
            [PropertyOrder(-196)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            public TabItemObject TabItem
            {
                get
                {
                    if (this.tabItem == null)
                        this.tabItem = new TabItemObject(this.owner);
                    return this.tabItem;
                }
            }

            private NavigationBarObject navigationBar;
            /// <summary>
            /// 导航栏
            /// </summary>
            [Description("导航栏")]
            [PropertyOrder(-194)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            public NavigationBarObject NavigationBar
            {
                get
                {
                    if (this.navigationBar == null)
                        this.navigationBar = new NavigationBarObject(this.owner);
                    return this.navigationBar;
                }
            }

            private TabControlPlusGlobalButttonCollection globalButttonCollection;
            /// <summary>
            /// 全局按钮集合
            /// </summary>
            [Description("全局按钮集合")]
            [PropertyOrder(-192)]
            [DefaultValue(null)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            public TabControlPlusGlobalButttonCollection GlobalButttons
            {
                get
                {
                    if (this.globalButttonCollection == null)
                        this.globalButttonCollection = new TabControlPlusGlobalButttonCollection(this.owner);
                    return this.globalButttonCollection;
                }
            }

            #endregion

            [TypeConverter(typeof(PropertyOrderConverter))]
            public class TabItemObject
            {
                private TabControlPlus owner = null;
                internal TabItemObject(TabControlPlus owner) { this.owner = owner; }

                #region 属性

                private RoundCorner roundSize = new RoundCorner(6, 6, 0, 0);
                /// <summary>
                /// 圆角
                /// </summary>
                [Description("圆角")]
                [PropertyOrder(-198)]
                [DefaultValue(typeof(RoundCorner), "6, 6, 0, 0")]
                public RoundCorner RoundSize
                {
                    get { return this.roundSize; }
                    set
                    {
                        if (this.roundSize == value || value.LeftTop < 0 || value.RightTop < 0 || value.LeftBottom < 0 || value.RightBottom < 0)
                            return;

                        this.roundSize = value;
                        if (this.owner != null)
                        {
                            this.owner.InitializeElement();
                            this.owner.Invalidate();
                        }
                    }
                }

                private bool roundQuality = true;
                /// <summary>
                /// 是否启用圆角抗锯齿功能
                /// </summary>
                [Description("是否启用圆角抗锯齿功能")]
                [PropertyOrder(-196)]
                [DefaultValue(true)]
                public bool RoundQuality
                {
                    get { return this.roundQuality; }
                    set
                    {
                        if (this.roundQuality == value)
                            return;

                        this.roundQuality = value;
                        if (this.owner != null)
                        {
                            this.owner.Invalidate();
                        }
                    }
                }

                private bool autoWidth = false;
                /// <summary>
                /// 是否自动宽度（通用）
                /// </summary>
                [Description("是否自动宽度（通用）")]
                [PropertyOrder(-192)]
                [DefaultValue(false)]
                public bool AutoWidth
                {
                    get { return this.autoWidth; }
                    set
                    {
                        if (this.autoWidth == value)
                            return;

                        this.autoWidth = value;
                        if (this.owner != null)
                        {
                            this.owner.InitializeElement();
                            this.owner.Invalidate();
                        }
                    }
                }

                private int autoWidthMin = 70;
                /// <summary>
                /// 自动宽度模式下最小宽度（通用）
                /// </summary>
                [Description("自动宽度模式下最小宽度（通用）")]
                [PropertyOrder(-190)]
                [DefaultValue(70)]
                public int AutoWidthMin
                {
                    get { return this.autoWidthMin; }
                    set
                    {
                        if (this.autoWidthMin == value || value < 0)
                            return;

                        this.autoWidthMin = value;
                        if (this.owner != null)
                        {
                            this.owner.InitializeElement();
                            this.owner.Invalidate();
                        }
                    }
                }

                private LRMargin lRMargin = new LRMargin(0, 0);
                /// <summary>
                /// 左右外边距（通用）
                /// </summary>
                [Description("左右外边距（通用）")]
                [PropertyOrder(-188)]
                [DefaultValue(typeof(LRMargin), "0, 0")]
                public LRMargin LRMargin
                {
                    get { return this.lRMargin; }
                    set
                    {
                        if (this.lRMargin == value || value.Left < 0 || value.Right < 0)
                            return;

                        this.lRMargin = value;
                        if (this.owner != null)
                        {
                            this.owner.InitializeElement();
                            this.owner.Invalidate();
                        }
                    }
                }

                private LRPadding lRPadding = new LRPadding(2, 2);
                /// <summary>
                /// 左右内边距（通用）
                /// </summary>
                [Description("左右内边距（通用）")]
                [PropertyOrder(-186)]
                [DefaultValue(typeof(LRPadding), "2, 2")]
                public LRPadding LRPadding
                {
                    get { return this.lRPadding; }
                    set
                    {
                        if (this.lRPadding == value || value.Left < 0 || value.Right < 0)
                            return;

                        this.lRPadding = value;
                        if (this.owner != null)
                        {
                            this.owner.InitializeElement();
                            this.owner.Invalidate();
                        }
                    }
                }

                private Size size = new Size(100, 24);
                /// <summary>
                /// Size（通用）
                /// </summary>
                [Description("Size（通用）")]
                [PropertyOrder(-185)]
                [DefaultValue(typeof(Size), "100, 24")]
                public Size Size
                {
                    get { return this.size; }
                    set
                    {
                        if (this.size == value || value.Width < 0 || value.Height < 0)
                            return;

                        this.size = value;
                        if (this.owner != null)
                        {
                            this.owner.InitializeElement();
                            this.owner.Invalidate();
                        }
                    }
                }

                private int contentOffset = 0;
                /// <summary>
                /// 内容上下方向布局偏移量
                /// </summary>
                [Description("内容上下方向布局偏移量")]
                [PropertyOrder(-184)]
                [DefaultValue(0)]
                public int ContentOffset
                {
                    get { return this.contentOffset; }
                    set
                    {
                        if (this.contentOffset == value)
                            return;

                        this.contentOffset = value;

                        this.owner.UpdateEveryOneTabItemRectangle();
                        if (this.owner != null)
                        {
                            this.owner.Invalidate();
                        }
                    }
                }

                private bool verticalLayout = false;
                /// <summary>
                /// 是否纵向布局(限于左右两边)
                /// </summary>
                [Description("是否纵向布局(限于左右两边)")]
                [PropertyOrder(-182)]
                [DefaultValue(false)]
                public bool VerticalLayout
                {
                    get { return this.verticalLayout; }
                    set
                    {
                        if (this.verticalLayout == value)
                            return;

                        this.verticalLayout = value;
                        if (this.owner.TabBar.Alignment == TabControlPlusTabBarAlignment.Left || this.owner.TabBar.Alignment == TabControlPlusTabBarAlignment.Right)
                        {
                            if (this.owner != null)
                            {
                                this.owner.InitializeElement();
                                this.owner.Invalidate();
                            }
                        }
                    }
                }

                private StringAlignment textAlignment = StringAlignment.Near;
                /// <summary>
                /// 文本对齐方式
                /// </summary>
                [Description("文本对齐方式")]
                [PropertyOrder(-178)]
                [DefaultValue(StringAlignment.Near)]
                public StringAlignment TextAlignment
                {
                    get { return this.textAlignment; }
                    set
                    {
                        if (this.textAlignment == value)
                            return;

                        this.textAlignment = value;
                        if (this.owner != null)
                        {
                            this.owner.InitializeElement();
                            this.owner.Invalidate();
                        }
                    }
                }

                private IconObject icon;
                /// <summary>
                /// 图标
                /// </summary>
                [Description("图标")]
                [PropertyOrder(-176)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                public IconObject Icon
                {
                    get
                    {
                        if (this.icon == null)
                            this.icon = new IconObject(this.owner);
                        return this.icon;
                    }
                }

                private CloseButtonObject closeButton;
                /// <summary>
                /// 关闭按钮
                /// </summary>
                [Description("关闭按钮")]
                [PropertyOrder(-174)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                public CloseButtonObject CloseButton
                {
                    get
                    {
                        if (this.closeButton == null)
                            this.closeButton = new CloseButtonObject(this.owner);
                        return this.closeButton;
                    }
                }

                private bool interchangeEnabled = false;
                /// <summary>
                /// 是否启用通过鼠标交换位置
                /// </summary>
                [Description("是否启用通过鼠标交换位置")]
                [PropertyOrder(-172)]
                [DefaultValue(false)]
                public bool InterchangeEnabled
                {
                    get { return this.interchangeEnabled; }
                    set
                    {
                        if (this.interchangeEnabled == value)
                            return;

                        this.interchangeEnabled = value;
                    }
                }

                private bool disableActivation = false;
                /// <summary>
                /// 是否允许切换到已禁用的
                /// </summary>
                [Description("是否允许切换到已禁用的")]
                [PropertyOrder(-170)]
                [DefaultValue(false)]
                public bool DisableActivation
                {
                    get { return this.disableActivation; }
                    set
                    {
                        if (this.disableActivation == value)
                            return;

                        this.disableActivation = value;
                    }
                }

                #endregion

                [TypeConverter(typeof(PropertyOrderConverter))]
                public class IconObject
                {
                    private TabControlPlus owner = null;
                    internal IconObject(TabControlPlus owner) { this.owner = owner; }

                    #region 属性

                    private bool visible = false;
                    /// <summary>
                    /// TabItem图标是否显示(通用)
                    /// </summary>
                    [Description("TabItem图标是否显示(通用)")]
                    [PropertyOrder(-138)]
                    [DefaultValue(false)]
                    public bool Visible
                    {
                        get { return this.visible; }
                        set
                        {
                            if (this.visible == value)
                                return;

                            this.visible = value;
                            if (this.owner != null)
                            {
                                this.owner.InitializeElement();
                                this.owner.Invalidate();
                            }
                        }
                    }

                    private Size size = new Size(14, 14);
                    /// <summary>
                    /// TabItem图标Size
                    /// </summary>
                    [Description("TabItem图标Size")]
                    [PropertyOrder(-136)]
                    [DefaultValue(typeof(Size), "14, 14")]
                    public Size Size
                    {
                        get { return this.size; }
                        set
                        {
                            if (this.size == value || value.Width < 0 || value.Height < 0)
                                return;

                            this.size = value;
                            if (this.owner != null)
                            {
                                this.owner.InitializeElement();
                                this.owner.Invalidate();
                            }
                        }
                    }

                    private LRMargin lRMargin = new LRMargin(0, 1);
                    /// <summary>
                    /// TabItem图标左右外边距
                    /// </summary>
                    [Description("TabItem图标左右外边距")]
                    [PropertyOrder(-134)]
                    [DefaultValue(typeof(LRMargin), "0, 1")]
                    public LRMargin LRMargin
                    {
                        get { return this.lRMargin; }
                        set
                        {
                            if (this.lRMargin == value || value.Left < 0 || value.Right < 0)
                                return;

                            this.lRMargin = value;
                            if (this.owner != null)
                            {
                                this.owner.InitializeElement();
                                this.owner.Invalidate();
                            }
                        }
                    }

                    #endregion

                }

                [TypeConverter(typeof(PropertyOrderConverter))]
                public class CloseButtonObject
                {
                    private TabControlPlus owner = null;
                    internal CloseButtonObject(TabControlPlus owner) { this.owner = owner; }

                    #region 属性

                    private bool visible = false;
                    /// <summary>
                    /// TabItem关闭按钮是否显示（通用）
                    /// </summary>
                    [Description("TabItem关闭按钮是否显示（通用）")]
                    [PropertyOrder(-128)]
                    [DefaultValue(false)]
                    public bool Visible
                    {
                        get { return this.visible; }
                        set
                        {
                            if (this.visible == value)
                                return;

                            this.visible = value;
                            if (this.owner != null)
                            {
                                this.owner.InitializeElement();
                                this.owner.Invalidate();
                            }
                        }
                    }

                    private TabControlPlusTabItemColseButtonAlignment alignment = TabControlPlusTabItemColseButtonAlignment.Right;
                    /// <summary>
                    /// TabItem关闭按钮对齐方式
                    /// </summary>
                    [Description("TabItem关闭按钮对齐方式")]
                    [PropertyOrder(-126)]
                    [DefaultValue(TabControlPlusTabItemColseButtonAlignment.Right)]
                    public TabControlPlusTabItemColseButtonAlignment Alignment
                    {
                        get { return this.alignment; }
                        set
                        {
                            if (this.alignment == value)
                                return;

                            this.alignment = value;
                            if (this.owner != null)
                            {
                                this.owner.InitializeElement();
                                this.owner.Invalidate();
                            }
                        }
                    }

                    private Size size = new Size(12, 12);
                    /// <summary>
                    /// TabItem关闭按钮Size
                    /// </summary>
                    [Description("TabItem关闭按钮Size")]
                    [PropertyOrder(-124)]
                    [DefaultValue(typeof(Size), "12, 12")]
                    public Size Size
                    {
                        get { return this.size; }
                        set
                        {
                            if (this.size == value || value.Width < 0 || value.Height < 0)
                                return;

                            this.size = value;
                            if (this.owner != null)
                            {
                                this.owner.InitializeElement();
                                this.owner.Invalidate();
                            }
                        }
                    }

                    private LRMargin lRMargin = new LRMargin(1, 0);
                    /// <summary>
                    /// TabItem关闭按钮左右外边距
                    /// </summary>
                    [Description("TabItem关闭按钮左右外边距")]
                    [PropertyOrder(-122)]
                    [DefaultValue(typeof(LRMargin), "1, 0")]
                    public LRMargin LRMargin
                    {
                        get { return this.lRMargin; }
                        set
                        {
                            if (this.lRMargin == value || value.Left < 0 || value.Right < 0)
                                return;

                            this.lRMargin = value;
                            if (this.owner != null)
                            {
                                this.owner.InitializeElement();
                                this.owner.Invalidate();
                            }
                        }
                    }

                    #endregion

                }

            }

            [TypeConverter(typeof(PropertyOrderConverter))]
            public class NavigationBarObject
            {
                private TabControlPlus owner = null;
                internal NavigationBarObject(TabControlPlus owner) { this.owner = owner; }

                #region 属性

                private bool visible = true;
                /// <summary>
                /// 是否显示导航栏
                /// </summary>
                [Description("是否显示导航栏")]
                [PropertyOrder(-200)]
                [DefaultValue(true)]
                public bool Visible
                {
                    get { return this.visible; }
                    set
                    {
                        if (this.visible == value)
                            return;

                        this.visible = value;
                        if (this.owner != null)
                        {
                            this.owner.InitializeElement();
                            this.owner.Invalidate();
                        }
                    }
                }

                private Size buttonSize = new Size(12, 12);
                /// <summary>
                /// 导航栏按钮Size
                /// </summary>
                [Description("导航栏按钮Size")]
                [PropertyOrder(-196)]
                [DefaultValue(typeof(Size), "12, 12")]
                public Size ButtonSize
                {
                    get { return this.buttonSize; }
                    set
                    {
                        if (this.buttonSize == value || value.Width < 0 || value.Height < 0)
                            return;

                        this.buttonSize = value;
                        if (this.owner != null)
                        {
                            this.owner.InitializeElement();
                            this.owner.Invalidate();
                        }
                    }
                }

                private LRMargin buttonLRMargin = new LRMargin(2, 2);
                /// <summary>
                /// 按钮左右外边距
                /// </summary>
                [Description("按钮左右外边距")]
                [PropertyOrder(-194)]
                [DefaultValue(typeof(LRMargin), "2,2")]
                public LRMargin ButtonLRMargin
                {
                    get { return this.buttonLRMargin; }
                    set
                    {
                        if (this.buttonLRMargin == value || value.Left < 0 || value.Right < 0)
                            return;

                        this.buttonLRMargin = value;
                        if (this.owner != null)
                        {
                            this.owner.InitializeElement();
                            this.owner.Invalidate();
                        }
                    }
                }

                private NavigationButtonObject prevButton;
                /// <summary>
                /// 上一个按钮
                /// </summary>
                [Browsable(false)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                public NavigationButtonObject PrevButton
                {
                    get
                    {
                        if (this.prevButton == null)
                            this.prevButton = new NavigationButtonObject(this.owner);
                        return this.prevButton;
                    }
                }

                private NavigationButtonObject nextButton;
                /// <summary>
                /// 下一个按钮
                /// </summary>
                [Browsable(false)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                public NavigationButtonObject NextButton
                {
                    get
                    {
                        if (this.nextButton == null)
                            this.nextButton = new NavigationButtonObject(this.owner);
                        return this.nextButton;
                    }
                }

                #endregion

                public class NavigationButtonObject
                {
                    private TabControlPlus owner = null;
                    internal NavigationButtonObject(TabControlPlus owner) { this.owner = owner; }

                    #region 属性

                    /// <summary>
                    /// 鼠标是否已进入
                    /// </summary>
                    [Browsable(false)]
                    public bool IsMouseEnter
                    {
                        get { return this.owner.IsMouseEnter(this); }
                    }

                    /// <summary>
                    /// 按钮rect(包括外边距)
                    /// </summary>
                    [Browsable(false)]
                    [EditorBrowsable(EditorBrowsableState.Never)]
                    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                    protected internal Rectangle M_Rect { get; set; }

                    /// <summary>
                    /// 按钮rect(不包括外边距、边框、内边距)
                    /// </summary>
                    [Browsable(false)]
                    [EditorBrowsable(EditorBrowsableState.Never)]
                    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                    protected internal Rectangle C_Rect { get; set; }

                    #endregion

                }

            }

        }

        [TypeConverter(typeof(PropertyOrderConverter))]
        public class PickerObject
        {
            private TabControlPlus owner = null;
            internal PickerObject(TabControlPlus owner) { this.owner = owner; }

            #region 属性

            private TabControlPlusPickerStylePattern stylePattern = TabControlPlusPickerStylePattern.GradualLine;
            /// <summary>
            /// 下拉面板风格模式
            /// </summary>
            [Description("下拉面板风格模式")]
            [PropertyOrder(-200)]
            [DefaultValue(TabControlPlusPickerStylePattern.GradualLine)]
            public TabControlPlusPickerStylePattern StylePattern
            {
                get { return this.stylePattern; }
                set
                {
                    if (this.stylePattern == value)
                        return;

                    this.stylePattern = value;
                }
            }

            private Size maxSize = new Size(400, 600);
            /// <summary>
            /// 下拉框最大Size
            /// </summary>
            [Description("下拉框最大Size")]
            [PropertyOrder(-188)]
            [DefaultValue(typeof(Size), "400,600")]
            public Size MaxSize
            {
                get { return this.maxSize; }
                set
                {
                    if (this.maxSize == value || value.Width < 0 || value.Height < 0)
                        return;

                    this.maxSize = value;
                }
            }

            private Font font = null;
            /// <summary>
            /// 字体
            /// </summary>
            [Description("字体")]
            [PropertyOrder(-184)]
            public Font Font
            {
                get
                {
                    if (this.font != null)
                    {
                        return this.font;
                    }
                    if (((TabControlPlus)this.owner).Parent != null)
                    {
                        return ((TabControlPlus)this.owner).Parent.Font;
                    }
                    return Control.DefaultFont;
                }
                set
                {
                    if (((TabControlPlus)this.owner).Parent != null)
                    {
                        if (((TabControlPlus)this.owner).Parent.Font.Equals(value))
                        {
                            this.font = null;
                            return;
                        }
                    }
                    if (Control.DefaultFont.Equals(value))
                    {
                        this.font = null;
                        return;
                    }

                    this.font = value;
                }
            }
            private bool ShouldSerializeFont()
            {
                return (this.font != null && !this.font.Equals(Control.DefaultFont));
            }
            private void ResetFont()
            {
                this.font = null;
            }

            private TabItemObject tabItem;
            /// <summary>
            /// TabItem
            /// </summary>
            [Description("TabItem")]
            [PropertyOrder(-182)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            public TabItemObject TabItem
            {
                get
                {
                    if (this.tabItem == null)
                        this.tabItem = new TabItemObject(this.owner);
                    return this.tabItem;
                }
            }

            private ScrollBarObject scrollBar;
            /// <summary>
            /// 滚动条
            /// </summary>
            [Description("滚动条")]
            [PropertyOrder(-180)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            public ScrollBarObject ScrollBar
            {
                get
                {
                    if (this.scrollBar == null)
                        this.scrollBar = new ScrollBarObject();
                    return this.scrollBar;
                }
            }

            #endregion

            [TypeConverter(typeof(PropertyOrderConverter))]
            public class TabItemObject
            {
                private TabControlPlus owner = null;
                internal TabItemObject(TabControlPlus owner) { this.owner = owner; }

                #region 属性

                private int height = 24;
                /// <summary>
                /// 高度
                /// </summary>
                [Description("高度")]
                [PropertyOrder(-188)]
                [DefaultValue(24)]
                public int Height
                {
                    get { return this.height; }
                    set
                    {
                        if (this.height == value || value < 0)
                            return;

                        this.height = value;
                    }
                }

                private LRPadding lRPadding = new LRPadding(3, 3);
                /// <summary>
                /// 左右内边距
                /// </summary>
                [Description("左右内边距")]
                [PropertyOrder(-186)]
                [DefaultValue(typeof(LRPadding), "3, 3")]
                public LRPadding LRPadding
                {
                    get { return this.lRPadding; }
                    set
                    {
                        if (value.Left < 0)
                            value.Left = 0;
                        if (value.Right < 0)
                            value.Right = 0;
                        if (this.lRPadding == value)
                            return;

                        this.lRPadding = value;
                    }
                }

                private bool iconVisible = false;
                /// <summary>
                /// 是否显示图标
                /// </summary>
                [Description("是否显示图标")]
                [PropertyOrder(-184)]
                [DefaultValue(false)]
                public bool IconVisible
                {
                    get { return this.iconVisible; }
                    set
                    {
                        if (this.iconVisible == value)
                            return;

                        this.iconVisible = value;
                    }
                }

                #endregion

            }

            [TypeConverter(typeof(PropertyOrderConverter))]
            public class ScrollBarObject
            {
                #region  属性

                private int trackThickness = 10;
                /// <summary>
                /// 轨道厚度
                /// </summary>
                [Description("轨道厚度")]
                [PropertyOrder(-100)]
                [DefaultValue(10)]
                public int TrackThickness
                {
                    get { return this.trackThickness; }
                    set
                    {
                        if (this.trackThickness == value || value < 0)
                            return;

                        this.trackThickness = value;
                    }
                }

                private int thumbMinSize = 26;
                /// <summary>
                /// 拇指最小高度
                /// </summary>
                [Description("拇指最小高度")]
                [PropertyOrder(-30)]
                [DefaultValue(26)]
                public int ThumbMinSize
                {
                    get { return this.thumbMinSize; }
                    set
                    {
                        if (this.thumbMinSize == value || value < 1)
                            return;

                        this.thumbMinSize = value;
                    }
                }

                /// <summary>
                /// 轨道Rect
                /// </summary>
                [Browsable(false)]
                [EditorBrowsable(EditorBrowsableState.Never)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                public Rectangle Track_Rect { get; set; }

                /// <summary>
                /// 拇指rect
                /// </summary>
                [Browsable(false)]
                [EditorBrowsable(EditorBrowsableState.Never)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                public RectangleF Thumb_Rect { get; set; }

                #endregion
            }

        }

        #endregion

        #region 外观

        public class StyleAppearanceObject : AppearanceObjectBase
        {
            internal StyleAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

            #region 属性

            private Color skinBackColor = Color.Empty;
            private readonly Color defaultBackColor = SystemColors.Control;
            private Color backColor = Color.Empty;
            /// <summary>
            /// 背景颜色
            /// </summary>
            [Description("背景颜色")]
            [PropertyOrder(-195)]
            [SkinProperty(true, true)]
            public Color BackColor
            {
                get
                {
                    if (this.owner.GetSkinObjectSkinStateCore() && this.skinBackColor != Color.Empty)
                    {
                        return this.skinBackColor;
                    }

                    if (this.backColor != Color.Empty)
                    {
                        return this.backColor;
                    }

                    if (((Control)this.owner).Parent != null)
                    {
                        return ((Control)this.owner).Parent.BackColor;
                    }

                    return this.defaultBackColor;
                }
                set
                {
                    if (this.backColor == value)
                        return;

                    this.backColor = value;
                    this.Invalidate();
                }
            }
            private bool ShouldSerializeBackColor()
            {
                return this.backColor != Color.Empty;
            }
            private void ResetBackColor()
            {
                this.backColor = Color.Empty;
                this.Invalidate();
            }

            private TabBarAppearanceObject tabBar;
            /// <summary>
            /// 选项卡栏
            /// </summary>
            [Description("选项卡栏")]
            [PropertyOrder(-192)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            [SkinProperty(true, false)]
            public TabBarAppearanceObject TabBar
            {
                get
                {
                    if (this.tabBar == null)
                        this.tabBar = new TabBarAppearanceObject(this.owner, this);
                    return this.tabBar;
                }
            }

            private BodyAppearanceObject body;
            /// <summary>
            /// 用于显示TabPage主体区域
            /// </summary>
            [Description("用于显示TabPage主体区域")]
            [PropertyOrder(-186)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            [SkinProperty(true, false)]
            public BodyAppearanceObject Body
            {
                get
                {
                    if (this.body == null)
                        this.body = new BodyAppearanceObject(this.owner, this);
                    return this.body;
                }
            }

            private PickerAppearanceObject picker;
            /// <summary>
            /// 用于显示TabPage主体区域
            /// </summary>
            [Description("用于显示TabPage主体区域")]
            [PropertyOrder(-186)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            [SkinProperty(true, false)]
            public PickerAppearanceObject Picker
            {
                get
                {
                    if (this.picker == null)
                        this.picker = new PickerAppearanceObject(this.owner, this);
                    return this.picker;
                }
            }

            private TipAppearanceObject tip;
            /// <summary>
            /// 提示信息
            /// </summary>
            [Description("提示信息")]
            [PropertyOrder(-186)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            [SkinProperty(true, false)]
            public TipAppearanceObject Tip
            {
                get
                {
                    if (this.tip == null)
                        this.tip = new TipAppearanceObject(this.owner, this);
                    return this.tip;
                }
            }

            #endregion

            public class TabBarAppearanceObject : AppearanceObjectBase
            {
                internal TabBarAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

                #region 属性

                private NavigationButtonAppearanceObject navigationButton;
                /// <summary>
                /// 导航栏按钮
                /// </summary>
                [Description("导航栏按钮")]
                [PropertyOrder(-192)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                [SkinProperty(true, false)]
                public NavigationButtonAppearanceObject NavigationButton
                {
                    get
                    {
                        if (this.navigationButton == null)
                            this.navigationButton = new NavigationButtonAppearanceObject(this.owner, this);
                        return this.navigationButton;
                    }
                }

                private TabItemAppearanceObject tabItem;
                /// <summary>
                /// 选项
                /// </summary>
                [Description("选项")]
                [PropertyOrder(-190)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                [SkinProperty(true, false)]
                public TabItemAppearanceObject TabItem
                {
                    get
                    {
                        if (this.tabItem == null)
                            this.tabItem = new TabItemAppearanceObject(this.owner, this);
                        return this.tabItem;
                    }
                }

                #endregion

                public class NavigationButtonAppearanceObject : AppearanceObjectBase
                {
                    internal NavigationButtonAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

                    #region 属性

                    private ItemAppearanceObject normal;
                    /// <summary>
                    /// 正常状态样式
                    /// </summary>
                    [Description("正常状态样式")]
                    [PropertyOrder(-194)]
                    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                    [SkinProperty(true, false)]
                    public ItemAppearanceObject Normal
                    {
                        get
                        {
                            if (this.normal == null)
                                this.normal = new ItemAppearanceObject(this.owner, this, SystemColors.ActiveCaption, SystemColors.GradientActiveCaption);
                            return this.normal;
                        }
                    }

                    private ItemAppearanceObject enter;
                    /// <summary>
                    /// 鼠标进入状态样式
                    /// </summary>
                    [Description("鼠标进入状态样式")]
                    [PropertyOrder(-192)]
                    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                    [SkinProperty(true, false)]
                    public ItemAppearanceObject Enter
                    {
                        get
                        {
                            if (this.enter == null)
                                this.enter = new ItemAppearanceObject(this.owner, this, SystemColors.ActiveCaption, SystemColors.ActiveCaption);
                            return this.enter;
                        }
                    }

                    #endregion

                    public class ItemAppearanceObject : AppearanceObjectBase
                    {
                        internal ItemAppearanceObject(ISkinObject owner, AppearanceObjectBase parent, Color borderColor, Color backColor) : base(owner, parent)
                        {
                            this.defaultBorderColor = borderColor;
                            this.defaultBackColor = backColor;
                        }

                        #region 属性

                        private Color skinBorderColor = Color.Empty;
                        private readonly Color defaultBorderColor = Color.Empty;
                        private Color borderColor = Color.Empty;
                        /// <summary>
                        /// 边框颜色
                        /// </summary>
                        [Description("边框颜色")]
                        [PropertyOrder(-159)]
                        [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
                        [SkinProperty(true, false)]
                        public Color BorderColor
                        {
                            get
                            {
                                if (this.owner.GetSkinObjectSkinStateCore())
                                {
                                    return this.skinBorderColor;
                                }

                                if (this.borderColor != Color.Empty)
                                {
                                    return this.borderColor;
                                }

                                return this.defaultBorderColor;
                            }
                            set
                            {
                                if (this.borderColor == value)
                                    return;

                                this.borderColor = value;
                                this.Invalidate();
                            }
                        }
                        private bool ShouldSerializeBorderColor()
                        {
                            return this.borderColor != Color.Empty;
                        }
                        private void ResetBorderColor()
                        {
                            this.borderColor = Color.Empty;
                            this.Invalidate();
                        }

                        private Color skinBackColor = Color.Empty;
                        private readonly Color defaultBackColor = Color.Empty;
                        private Color backColor = Color.Empty;
                        /// <summary>
                        /// 背景颜色
                        /// </summary>
                        [Description("背景颜色")]
                        [PropertyOrder(-158)]
                        [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
                        [SkinProperty(true, false)]
                        public Color BackColor
                        {
                            get
                            {
                                if (this.owner.GetSkinObjectSkinStateCore())
                                {
                                    return this.skinBackColor;
                                }

                                if (this.backColor != Color.Empty)
                                {
                                    return this.backColor;
                                }

                                return this.defaultBackColor;
                            }
                            set
                            {
                                if (this.backColor == value)
                                    return;

                                this.backColor = value;
                                this.Invalidate();
                            }
                        }
                        private bool ShouldSerializeBackColor()
                        {
                            return this.backColor != Color.Empty;
                        }
                        private void ResetBackColor()
                        {
                            this.backColor = Color.Empty;
                            this.Invalidate();
                        }

                        #endregion

                    }

                }

                public class TabItemAppearanceObject : AppearanceObjectBase
                {
                    internal TabItemAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

                    #region 属性

                    private ItemAppearanceObject normal;
                    /// <summary>
                    /// 正常状态样式
                    /// </summary>
                    [Description("正常状态样式")]
                    [PropertyOrder(-194)]
                    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                    [SkinProperty(true, false)]
                    public ItemAppearanceObject Normal
                    {
                        get
                        {
                            if (this.normal == null)
                                this.normal = new ItemAppearanceObject(this.owner, this, SystemColors.GradientActiveCaption, SystemColors.Window);
                            return this.normal;
                        }
                    }

                    private ItemAppearanceObject enter;
                    /// <summary>
                    /// 鼠标进入状态样式
                    /// </summary>
                    [Description("鼠标进入状态样式")]
                    [PropertyOrder(-192)]
                    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                    [SkinProperty(true, false)]
                    public ItemAppearanceObject Enter
                    {
                        get
                        {
                            if (this.enter == null)
                                this.enter = new ItemAppearanceObject(this.owner, this, SystemColors.ActiveCaption, SystemColors.Window);
                            return this.enter;
                        }
                    }

                    private ItemAppearanceObject selected;
                    /// <summary>
                    /// 选中状态样式
                    /// </summary>
                    [Description("选中状态样式")]
                    [PropertyOrder(-190)]
                    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                    [SkinProperty(true, false)]
                    public ItemAppearanceObject Selected
                    {
                        get
                        {
                            if (this.selected == null)
                                this.selected = new ItemAppearanceObject(this.owner, this, SystemColors.ActiveCaption, SystemColors.Window);
                            return this.selected;
                        }
                    }

                    private ItemAppearanceObject disabled;
                    /// <summary>
                    /// 禁用状态样式
                    /// </summary>
                    [Description("禁用状态样式")]
                    [PropertyOrder(-188)]
                    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                    [SkinProperty(true, false)]
                    public ItemAppearanceObject Disabled
                    {
                        get
                        {
                            if (this.disabled == null)
                                this.disabled = new ItemAppearanceObject(this.owner, this, SystemColors.InactiveCaption, SystemColors.Window);
                            return this.disabled;
                        }
                    }

                    private CloseButtonAppearanceObject closeButton;
                    /// <summary>
                    /// 关闭按钮
                    /// </summary>
                    [Description("关闭按钮")]
                    [PropertyOrder(-142)]
                    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                    [SkinProperty(true, false)]
                    public CloseButtonAppearanceObject CloseButton
                    {
                        get
                        {
                            if (this.closeButton == null)
                                this.closeButton = new CloseButtonAppearanceObject(this.owner, this);
                            return this.closeButton;
                        }
                    }

                    #endregion

                    public class ItemAppearanceObject : AppearanceObjectBase
                    {
                        internal ItemAppearanceObject(ISkinObject owner, AppearanceObjectBase parent, Color backColor, Color textColor) : base(owner, parent)
                        {
                            this.defaultBackColor = backColor;
                            this.defaultTextColor = textColor;
                        }

                        #region 属性

                        private Color skinBackColor = Color.Empty;
                        private readonly Color defaultBackColor = Color.Empty;
                        private Color backColor = Color.Empty;
                        /// <summary>
                        /// 背景颜色
                        /// </summary>
                        [Description("背景颜色")]
                        [PropertyOrder(-158)]
                        [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
                        [SkinProperty(true, false)]
                        public Color BackColor
                        {
                            get
                            {
                                if (this.owner.GetSkinObjectSkinStateCore())
                                {
                                    return this.skinBackColor;
                                }

                                if (this.backColor != Color.Empty)
                                {
                                    return this.backColor;
                                }

                                return this.defaultBackColor;
                            }
                            set
                            {
                                if (this.backColor == value)
                                    return;

                                this.backColor = value;
                                this.Invalidate();
                            }
                        }
                        private bool ShouldSerializeBackColor()
                        {
                            return this.backColor != Color.Empty;
                        }
                        private void ResetBackColor()
                        {
                            this.backColor = Color.Empty;
                            this.Invalidate();
                        }

                        private Color skinTextColor = Color.Empty;
                        private readonly Color defaultTextColor = Color.Empty;
                        private Color textColor = Color.Empty;
                        /// <summary>
                        /// 文本颜色
                        /// </summary>
                        [Description("文本颜色")]
                        [PropertyOrder(-157)]
                        [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
                        [SkinProperty(true, false)]
                        public Color TextColor
                        {
                            get
                            {
                                if (this.owner.GetSkinObjectSkinStateCore())
                                {
                                    return this.skinTextColor;
                                }

                                if (this.textColor != Color.Empty)
                                {
                                    return this.textColor;
                                }

                                return this.defaultTextColor;
                            }
                            set
                            {
                                if (this.textColor == value)
                                    return;

                                this.textColor = value;
                                this.Invalidate();
                            }
                        }
                        private bool ShouldSerializeTextColor()
                        {
                            return this.textColor != Color.Empty;
                        }
                        private void ResetTextColor()
                        {
                            this.textColor = Color.Empty;
                            this.Invalidate();
                        }

                        #endregion

                    }

                    public class CloseButtonAppearanceObject : AppearanceObjectBase
                    {
                        internal CloseButtonAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

                        #region 属性

                        private ItemAppearanceObject normal;
                        /// <summary>
                        /// 正常状态样式
                        /// </summary>
                        [Description("正常状态样式")]
                        [PropertyOrder(-194)]
                        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                        [SkinProperty(true, false)]
                        public ItemAppearanceObject Normal
                        {
                            get
                            {
                                if (this.normal == null)
                                    this.normal = new ItemAppearanceObject(this.owner, this, Color.Empty, SystemColors.Window);
                                return this.normal;
                            }
                        }

                        private ItemAppearanceObject enter;
                        /// <summary>
                        /// 鼠标进入状态样式
                        /// </summary>
                        [Description("鼠标进入状态样式")]
                        [PropertyOrder(-192)]
                        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                        [SkinProperty(true, false)]
                        public ItemAppearanceObject Enter
                        {
                            get
                            {
                                if (this.enter == null)
                                    this.enter = new ItemAppearanceObject(this.owner, this, Color.Empty, SystemColors.Window);
                                return this.enter;
                            }
                        }

                        private ItemAppearanceObject disabled;
                        /// <summary>
                        /// 禁用状态样式
                        /// </summary>
                        [Description("禁用状态样式")]
                        [PropertyOrder(-190)]
                        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                        [SkinProperty(true, false)]
                        public ItemAppearanceObject Disabled
                        {
                            get
                            {
                                if (this.disabled == null)
                                    this.disabled = new ItemAppearanceObject(this.owner, this, Color.Empty, SystemColors.InactiveBorder);
                                return this.disabled;
                            }
                        }

                        #endregion

                        public class ItemAppearanceObject : AppearanceObjectBase
                        {
                            internal ItemAppearanceObject(ISkinObject owner, AppearanceObjectBase parent, Color backColor, Color foreColor) : base(owner, parent)
                            {
                                this.defaultBackColor = backColor;
                                this.defaultForeColor = foreColor;
                            }

                            #region 属性

                            private Color skinBackColor = Color.Empty;
                            private readonly Color defaultBackColor = Color.Empty;
                            private Color backColor = Color.Empty;
                            /// <summary>
                            /// 背景颜色
                            /// </summary>
                            [Description("背景颜色")]
                            [PropertyOrder(-158)]
                            [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
                            [SkinProperty(true, false)]
                            public Color BackColor
                            {
                                get
                                {
                                    if (this.owner.GetSkinObjectSkinStateCore())
                                    {
                                        return this.skinBackColor;
                                    }

                                    if (this.backColor != Color.Empty)
                                    {
                                        return this.backColor;
                                    }

                                    return this.defaultBackColor;
                                }
                                set
                                {
                                    if (this.backColor == value)
                                        return;

                                    this.backColor = value;
                                    this.Invalidate();
                                }
                            }
                            private bool ShouldSerializeBackColor()
                            {
                                return this.backColor != Color.Empty;
                            }
                            private void ResetBackColor()
                            {
                                this.backColor = Color.Empty;
                                this.Invalidate();
                            }

                            private Color skinForeColor = Color.Empty;
                            private Color defaultForeColor = Color.Empty;
                            private Color foreColor = Color.Empty;
                            /// <summary>
                            /// 前景颜色
                            /// </summary>
                            [Description("前景颜色")]
                            [PropertyOrder(-154)]
                            [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
                            [SkinProperty(true, false)]
                            public Color ForeColor
                            {
                                get
                                {
                                    if (this.owner.GetSkinObjectSkinStateCore())
                                    {
                                        return this.skinForeColor;
                                    }

                                    if (this.foreColor != Color.Empty)
                                    {
                                        return this.foreColor;
                                    }

                                    return this.defaultForeColor;
                                }
                                set
                                {
                                    if (this.foreColor == value)
                                        return;

                                    this.foreColor = value;
                                    this.Invalidate();
                                }
                            }
                            private bool ShouldSerializeForeColor()
                            {
                                return this.foreColor != Color.Empty;
                            }
                            private void ResetForeColor()
                            {
                                this.foreColor = Color.Empty;
                                this.Invalidate();
                            }

                            #endregion

                        }

                    }

                }

            }

            public class BodyAppearanceObject : AppearanceObjectBase
            {
                internal BodyAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

                #region 属性

                private Color skinBorderColor = Color.Empty;
                private readonly Color defaultBorderColor = SystemColors.ActiveCaption;
                private Color borderColor = Color.Empty;
                /// <summary>
                /// 主体区域框边框颜色
                /// </summary>
                [Description("主体区域框边框颜色")]
                [PropertyOrder(-108)]
                [SkinProperty(true, false)]
                public Color BorderColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinBorderColor;
                        }

                        if (this.borderColor != Color.Empty)
                        {
                            return this.borderColor;
                        }

                        return this.defaultBorderColor;
                    }
                    set
                    {
                        if (this.borderColor == value)
                            return;

                        this.borderColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeBorderColor()
                {
                    return this.borderColor != Color.Empty;
                }
                private void ResetBorderColor()
                {
                    this.borderColor = Color.Empty;
                    this.Invalidate();
                }

                private Color skinBackColor = Color.Empty;
                private readonly Color defaultBackColor = SystemColors.Window;
                private Color backColor = Color.Empty;
                /// <summary>
                /// 主体区域背景色
                /// </summary>
                [Description("主体区域背景色")]
                [PropertyOrder(-106)]
                [SkinProperty(true, false)]
                public Color BackColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinBackColor;
                        }

                        if (this.backColor != Color.Empty)
                        {
                            return this.backColor;
                        }

                        return this.defaultBackColor;
                    }
                    set
                    {
                        if (this.backColor == value)
                            return;

                        this.backColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeBackColor()
                {
                    return this.backColor != Color.Empty;
                }
                private void ResetBackColor()
                {
                    this.backColor = Color.Empty;
                    this.Invalidate();
                }

                #endregion

            }

            public class PickerAppearanceObject : AppearanceObjectBase
            {
                internal PickerAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

                #region 属性

                private Color skinBorderColor = Color.Empty;
                private readonly Color defaultBorderColor = SystemColors.ActiveCaption;
                private Color borderColor = Color.Empty;
                /// <summary>
                /// 下拉面板边框颜色
                /// </summary>
                [Description(" 下拉面板边框颜色")]
                [PropertyOrder(-198)]
                [SkinProperty(true, false)]
                public Color BorderColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinBorderColor;
                        }

                        if (this.borderColor != Color.Empty)
                        {
                            return this.borderColor;
                        }

                        return this.defaultBorderColor;
                    }
                    set
                    {
                        if (this.borderColor == value)
                            return;

                        this.borderColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeBorderColor()
                {
                    return this.borderColor != Color.Empty;
                }
                private void ResetBorderColor()
                {
                    this.borderColor = Color.Empty;
                    this.Invalidate();
                }

                private Color skinBackColor = Color.Empty;
                private readonly Color defaultBackColor = SystemColors.Window;
                private Color backColor = Color.Empty;
                /// <summary>
                /// 下拉面板背景颜色
                /// </summary>
                [Description(" 下拉面板背景颜色")]
                [PropertyOrder(-196)]
                [SkinProperty(true, false)]
                public Color BackColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinBackColor;
                        }

                        if (this.backColor != Color.Empty)
                        {
                            return this.backColor;
                        }

                        return this.defaultBackColor;
                    }
                    set
                    {
                        if (this.backColor == value)
                            return;

                        this.backColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeBackColor()
                {
                    return this.backColor != Color.Empty;
                }
                private void ResetBackColor()
                {
                    this.backColor = Color.Empty;
                    this.Invalidate();
                }

                private TabItemAppearanceObject tabItem;
                /// <summary>
                /// TabItem
                /// </summary>
                [Description("TabItem")]
                [PropertyOrder(-186)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                [SkinProperty(true, false)]
                public TabItemAppearanceObject TabItem
                {
                    get
                    {
                        if (this.tabItem == null)
                            this.tabItem = new TabItemAppearanceObject(this.owner, this);
                        return this.tabItem;
                    }
                }

                private ScrollBarAppearanceObject scrollBar;
                /// <summary>
                /// 滚动条
                /// </summary>
                [Description("滚动条")]
                [PropertyOrder(-184)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                [SkinProperty(true, false)]
                public ScrollBarAppearanceObject ScrollBar
                {
                    get
                    {
                        if (this.scrollBar == null)
                            this.scrollBar = new ScrollBarAppearanceObject(this.owner, this);
                        return this.scrollBar;
                    }
                }

                #endregion

                public class TabItemAppearanceObject : AppearanceObjectBase
                {
                    internal TabItemAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

                    #region 属性

                    private Color skinSplitterColor = Color.Empty;
                    private readonly Color defaultSplitterColor = SystemColors.GradientInactiveCaption;
                    private Color splitterColor = Color.Empty;
                    /// <summary>
                    /// 分隔线颜色
                    /// </summary>
                    [Description(" 分隔线颜色")]
                    [PropertyOrder(-198)]
                    [SkinProperty(true, false)]
                    public Color SplitterColor
                    {
                        get
                        {
                            if (this.owner.GetSkinObjectSkinStateCore())
                            {
                                return this.skinSplitterColor;
                            }

                            if (this.splitterColor != Color.Empty)
                            {
                                return this.splitterColor;
                            }

                            return this.defaultSplitterColor;
                        }
                        set
                        {
                            if (this.splitterColor == value)
                                return;

                            this.splitterColor = value;
                            this.Invalidate();
                        }
                    }
                    private bool ShouldSerializeSplitterColor()
                    {
                        return this.splitterColor != Color.Empty;
                    }
                    private void ResetSplitterColor()
                    {
                        this.splitterColor = Color.Empty;
                        this.Invalidate();
                    }

                    private ItemAppearanceObject normal;
                    /// <summary>
                    /// 正常状态样式
                    /// </summary>
                    [Description("正常状态样式")]
                    [PropertyOrder(-194)]
                    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                    [SkinProperty(true, false)]
                    public ItemAppearanceObject Normal
                    {
                        get
                        {
                            if (this.normal == null)
                                this.normal = new ItemAppearanceObject(this.owner, this, Color.White, Color.Gray);
                            return this.normal;
                        }
                    }

                    private ItemAppearanceObject enter;
                    /// <summary>
                    /// 鼠标进入状态样式
                    /// </summary>
                    [Description("鼠标进入状态样式")]
                    [PropertyOrder(-192)]
                    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                    [SkinProperty(true, false)]
                    public ItemAppearanceObject Enter
                    {
                        get
                        {
                            if (this.enter == null)
                                this.enter = new ItemAppearanceObject(this.owner, this, Color.FromArgb(130, 178, 178), Color.White);
                            return this.enter;
                        }
                    }

                    private ItemAppearanceObject disabled;
                    /// <summary>
                    /// 禁用状态样式
                    /// </summary>
                    [Description("禁用状态样式")]
                    [PropertyOrder(-190)]
                    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                    [SkinProperty(true, false)]
                    public ItemAppearanceObject Disabled
                    {
                        get
                        {
                            if (this.disabled == null)
                                this.disabled = new ItemAppearanceObject(this.owner, this, Color.Gray, Color.White);
                            return this.disabled;
                        }
                    }

                    #endregion

                    public class ItemAppearanceObject : AppearanceObjectBase
                    {
                        internal ItemAppearanceObject(ISkinObject owner, AppearanceObjectBase parent, Color backColor, Color textColor) : base(owner, parent)
                        {
                            this.defaultBackColor = backColor;
                            this.defaultTextColor = textColor;
                        }

                        #region 属性

                        private Color skinBackColor = Color.Empty;
                        private readonly Color defaultBackColor = Color.Empty;
                        private Color backColor = Color.Empty;
                        /// <summary>
                        /// 背景颜色
                        /// </summary>
                        [Description("背景颜色")]
                        [PropertyOrder(-158)]
                        [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
                        [SkinProperty(true, false)]
                        public Color BackColor
                        {
                            get
                            {
                                if (this.owner.GetSkinObjectSkinStateCore())
                                {
                                    return this.skinBackColor;
                                }

                                if (this.backColor != Color.Empty)
                                {
                                    return this.backColor;
                                }

                                return this.defaultBackColor;
                            }
                            set
                            {
                                if (this.backColor == value)
                                    return;

                                this.backColor = value;
                                this.Invalidate();
                            }
                        }
                        private bool ShouldSerializeBackColor()
                        {
                            return this.backColor != Color.Empty;
                        }
                        private void ResetBackColor()
                        {
                            this.backColor = Color.Empty;
                            this.Invalidate();
                        }

                        private Color skinTextColor = Color.Empty;
                        private readonly Color defaultTextColor = Color.Empty;
                        private Color textColor = Color.Empty;
                        /// <summary>
                        /// 文本颜色
                        /// </summary>
                        [Description("文本颜色")]
                        [PropertyOrder(-157)]
                        [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
                        [SkinProperty(true, false)]
                        public Color TextColor
                        {
                            get
                            {
                                if (this.owner.GetSkinObjectSkinStateCore())
                                {
                                    return this.skinTextColor;
                                }

                                if (this.textColor != Color.Empty)
                                {
                                    return this.textColor;
                                }

                                return this.defaultTextColor;
                            }
                            set
                            {
                                if (this.textColor == value)
                                    return;

                                this.textColor = value;
                                this.Invalidate();
                            }
                        }
                        private bool ShouldSerializeTextColor()
                        {
                            return this.textColor != Color.Empty;
                        }
                        private void ResetTextColor()
                        {
                            this.textColor = Color.Empty;
                            this.Invalidate();
                        }

                        #endregion

                    }

                }

                public class ScrollBarAppearanceObject : AppearanceObjectBase
                {
                    internal ScrollBarAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

                    #region  属性

                    private Color skinTrackBackColor = Color.Empty;
                    private readonly Color defaultTrackBackColor = SystemColors.ScrollBar;
                    private Color trackBackColor = Color.Empty;
                    /// <summary>
                    /// 轨道背景颜色
                    /// </summary>
                    [Description("轨道背景颜色")]
                    [PropertyOrder(-139)]
                    [SkinProperty(true, false)]
                    public Color TrackBackColor
                    {
                        get
                        {
                            if (this.owner.GetSkinObjectSkinStateCore())
                            {
                                return this.skinTrackBackColor;
                            }

                            if (this.trackBackColor != Color.Empty)
                            {
                                return this.trackBackColor;
                            }

                            return this.defaultTrackBackColor;
                        }
                        set
                        {
                            if (this.trackBackColor == value)
                                return;

                            this.trackBackColor = value;
                            this.Invalidate();
                        }
                    }
                    private bool ShouldSerializeTrackBackColor()
                    {
                        return this.trackBackColor != Color.Empty;
                    }
                    private void ResetTrackBackColor()
                    {
                        this.trackBackColor = Color.Empty;
                        this.Invalidate();
                    }

                    private Color skinThumbBackColor = Color.Empty;
                    private readonly Color defaultThumbBackColor = SystemColors.WindowFrame;
                    private Color thumbBackColor = Color.Empty;
                    /// <summary>
                    /// 拇指背景颜色
                    /// </summary>
                    [Description("拇指背景颜色")]
                    [PropertyOrder(-134)]
                    [SkinProperty(true, false)]
                    public Color ThumbBackColor
                    {
                        get
                        {
                            if (this.owner.GetSkinObjectSkinStateCore())
                            {
                                return this.skinThumbBackColor;
                            }

                            if (this.thumbBackColor != Color.Empty)
                            {
                                return this.thumbBackColor;
                            }

                            return this.defaultThumbBackColor;
                        }
                        set
                        {
                            if (this.thumbBackColor == value)
                                return;

                            this.thumbBackColor = value;
                            this.Invalidate();
                        }
                    }
                    private bool ShouldSerializeThumbBackColor()
                    {
                        return this.thumbBackColor != Color.Empty;
                    }
                    private void ResetThumbBackColor()
                    {
                        this.thumbBackColor = Color.Empty;
                        this.Invalidate();
                    }

                    #endregion

                }

            }

            public class TipAppearanceObject : AppearanceObjectBase
            {
                internal TipAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

                #region 属性

                private Color skinBorderColor = Color.Empty;
                private readonly Color defaultBorderColor = SystemColors.ActiveCaption;
                private Color borderColor = Color.Empty;
                /// <summary>
                /// 边框颜色
                /// </summary>
                [Description("边框颜色")]
                [PropertyOrder(-159)]
                [SkinProperty(true, false)]
                public Color BorderColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinBorderColor;
                        }

                        if (this.borderColor != Color.Empty)
                        {
                            return this.borderColor;
                        }

                        return this.defaultBorderColor;
                    }
                    set
                    {
                        if (this.borderColor == value)
                            return;

                        this.borderColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeBorderColor()
                {
                    return this.borderColor != Color.Empty;
                }
                private void ResetBorderColor()
                {
                    this.borderColor = Color.Empty;
                    this.Invalidate();
                }

                private Color skinBackColor = Color.Empty;
                private readonly Color defaultBackColor = SystemColors.GradientActiveCaption;
                private Color backColor = Color.Empty;
                /// <summary>
                /// 提示信息背景颜色
                /// </summary>
                [Description("提示信息背景颜色")]
                [PropertyOrder(-158)]
                [SkinProperty(true, false)]
                public Color BackColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinBackColor;
                        }

                        if (this.backColor != Color.Empty)
                        {
                            return this.backColor;
                        }

                        return this.defaultBackColor;
                    }
                    set
                    {
                        if (this.backColor == value)
                            return;

                        this.backColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeBackColor()
                {
                    return this.backColor != Color.Empty;
                }
                private void ResetBackColor()
                {
                    this.backColor = Color.Empty;
                    this.Invalidate();
                }

                private Color skinTextColor = Color.Empty;
                private readonly Color defaultTextColor = SystemColors.Window;
                private Color textColor = Color.Empty;
                /// <summary>
                /// 提示信息文本颜色
                /// </summary>
                [Description("提示信息文本颜色")]
                [PropertyOrder(-157)]
                [SkinProperty(true, false)]
                public Color TextColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinTextColor;
                        }

                        if (this.textColor != Color.Empty)
                        {
                            return this.textColor;
                        }

                        return this.defaultTextColor;
                    }
                    set
                    {
                        if (this.textColor == value)
                            return;

                        this.textColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeTextColor()
                {
                    return this.textColor != Color.Empty;
                }
                private void ResetTextColor()
                {
                    this.textColor = Color.Empty;
                    this.Invalidate();
                }

                #endregion

            }

        }

        #endregion

    }

}
